Update Pong/test/widget_test.dart

main
Benjamin Löffler 2024-01-11 02:38:41 +01:00
parent dc065306a7
commit 9bc3a866a1
1 changed files with 10 additions and 3 deletions

View File

@ -5,36 +5,43 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pong/main.dart'; import 'package:pong/main.dart';
void main() { void main() {
// Widget test for the "Berühren um zu beginnen!" message
testWidgets('Tests "Berühren um zu beginnen!"', (WidgetTester tester) async { testWidgets('Tests "Berühren um zu beginnen!"', (WidgetTester tester) async {
final tapToStart = find.text("Berühren um zu beginnen!"); final tapToStart = find.text("Berühren um zu beginnen!");
// Build the widget tree with StartScreen and pump the widget tree
await tester.pumpWidget(const MaterialApp(home: StartScreen())); await tester.pumpWidget(const MaterialApp(home: StartScreen()));
// Verify that the "Berühren um zu beginnen!" text is displayed
expect(tapToStart, findsOneWidget); expect(tapToStart, findsOneWidget);
}); });
// Widget test for the "Punkte:" message in GameScreen
testWidgets('Tests "Punkte:"', (WidgetTester tester) async { testWidgets('Tests "Punkte:"', (WidgetTester tester) async {
final points = find.text("Punkte: 0"); final points = find.text("Punkte: 0");
// Build the widget tree with GameScreen and pump the widget tree
await tester.pumpWidget(const MaterialApp(home: GameScreen())); await tester.pumpWidget(const MaterialApp(home: GameScreen()));
// Verify that the "Punkte: 0" text is displayed
expect(points, findsOneWidget); expect(points, findsOneWidget);
}); });
// Widget test for the UI of StartScreen
testWidgets('StartScreen UI Test', (WidgetTester tester) async { testWidgets('StartScreen UI Test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const MaterialApp( await tester.pumpWidget(const MaterialApp(
home: StartScreen(), home: StartScreen(),
)); ));
// Verify that the "Berühren um zu beginnen!" Text angezeigt wird. // Verify that the "Berühren um zu beginnen!" Text is displayed.
expect(find.text('Berühren um zu beginnen!'), findsOneWidget); expect(find.text('Berühren um zu beginnen!'), findsOneWidget);
// Tap auf das GestureDetector, um zur GameScreen zu wechseln. // Tap on the GestureDetector to navigate to GameScreen.
await tester.tap(find.byType(GestureDetector)); await tester.tap(find.byType(GestureDetector));
await tester.pump(); await tester.pump();
// Verify, dass der Übergang zur GameScreen erfolgt ist. // Verify that the transition to GameScreen has occurred.
expect(find.byType(GameScreen), findsOneWidget); expect(find.byType(GameScreen), findsOneWidget);
}); });
} }