parent
f29589d55b
commit
74745f35a3
@ -0,0 +1,4 @@ |
|||||||
|
class BenchmarkCounters { |
||||||
|
static var cartButton = 0; |
||||||
|
static var userSwitch = 0; |
||||||
|
} |
@ -1,6 +1,9 @@ |
|||||||
import 'package:flutter/material.dart'; |
import 'package:flutter/material.dart'; |
||||||
import 'package:thesis_shop/app.dart'; |
import 'package:thesis_shop/app.dart'; |
||||||
|
import 'package:thesis_shop/service/product_service.dart'; |
||||||
|
|
||||||
void main() { |
void main() { |
||||||
runApp(const ThesisShopApp()); |
runApp(ThesisShopApp( |
||||||
|
productService: ProductService(), |
||||||
|
)); |
||||||
} |
} |
||||||
|
@ -0,0 +1,49 @@ |
|||||||
|
// ignore_for_file: avoid_print |
||||||
|
|
||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:flutter_test/flutter_test.dart'; |
||||||
|
import 'package:thesis_shop/app.dart'; |
||||||
|
import 'package:thesis_shop/benchmark_counter.dart'; |
||||||
|
|
||||||
|
import 'product_service_mock.dart'; |
||||||
|
|
||||||
|
void main() { |
||||||
|
testWidgets('Efficiency Test', (WidgetTester tester) async { |
||||||
|
await tester |
||||||
|
.pumpWidget(ThesisShopApp(productService: MockedProductService())); |
||||||
|
await tester.pumpAndSettle(const Duration(seconds: 2)); |
||||||
|
final addIcons = find.byIcon(Icons.add); |
||||||
|
expect(addIcons, findsWidgets); |
||||||
|
// click at the first and last one 2 times |
||||||
|
await tester.tap(addIcons.first); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
await tester.tap(addIcons.first); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
await tester.tap(addIcons.last); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
await tester.tap(addIcons.last); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
|
||||||
|
// click on the first remove icon |
||||||
|
final removeIcons = find.byIcon(Icons.remove); |
||||||
|
await tester.tap(removeIcons.first); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
|
||||||
|
// toggle sign in button two times |
||||||
|
final switchButton = find.byKey(Key('user_switch')); |
||||||
|
await tester.tap(switchButton); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
await tester.tap(switchButton); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
|
||||||
|
// go to cart |
||||||
|
final cartButton = find.byKey(Key('cart_button')); |
||||||
|
await tester.tap(cartButton); |
||||||
|
await tester.pumpAndSettle(); |
||||||
|
final header = find.text('Warenkorb'); |
||||||
|
expect(header, findsOneWidget); |
||||||
|
|
||||||
|
print("cartButton: ${BenchmarkCounters.cartButton}"); |
||||||
|
print("userSwitch: ${BenchmarkCounters.userSwitch}"); |
||||||
|
}); |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
import 'package:thesis_shop/models/product.dart'; |
||||||
|
import 'package:thesis_shop/service/product_service.dart'; |
||||||
|
|
||||||
|
class MockedProductService implements ProductService { |
||||||
|
@override |
||||||
|
Future<List<Product>> fetchProducts() async { |
||||||
|
return const [ |
||||||
|
Product(title: 'Bananen', price: 3), |
||||||
|
Product(title: 'Äpfel', price: 2), |
||||||
|
Product(title: 'Birnen', price: 2.5), |
||||||
|
Product(title: 'Kirschen', price: 1.2), |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
String get url => throw UnimplementedError(); |
||||||
|
} |
@ -1,16 +0,0 @@ |
|||||||
// This is a basic Flutter widget test. |
|
||||||
// |
|
||||||
// To perform an interaction with a widget in your test, use the WidgetTester |
|
||||||
// utility that Flutter provides. For example, you can send tap and scroll |
|
||||||
// gestures. You can also use WidgetTester to find child widgets in the widget |
|
||||||
// tree, read text, and verify that the values of widget properties are correct. |
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart'; |
|
||||||
import 'package:thesis_shop/app.dart'; |
|
||||||
|
|
||||||
void main() { |
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async { |
|
||||||
// Build our app and trigger a frame. |
|
||||||
await tester.pumpWidget(const ThesisShopApp()); |
|
||||||
}); |
|
||||||
} |
|
Loading…
Reference in new issue