From 59198620a8d26ea47329158851bff4d86eed1a71 Mon Sep 17 00:00:00 2001 From: Fernando Martin Garcia Del Angel Date: Mon, 17 Feb 2020 16:52:38 -0600 Subject: [PATCH] Created widget testing with the built-in tool Finalized Testing --- .idea/workspace.xml | 152 ++++++++++++++--------------- eight_queens/test/widget_test.dart | 81 ++++++++++++--- 2 files changed, 139 insertions(+), 94 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index cadd1a8..a7add08 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,6 @@ - - - - @@ -115,9 +111,9 @@ - + @@ -176,39 +172,39 @@ - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -267,12 +263,12 @@ - + - + @@ -339,37 +335,37 @@ - + - - + + + + + - + - - - - - - + + - + - - + + - + - - + + - + + diff --git a/eight_queens/test/widget_test.dart b/eight_queens/test/widget_test.dart index f1b9d21..ff352f5 100644 --- a/eight_queens/test/widget_test.dart +++ b/eight_queens/test/widget_test.dart @@ -5,26 +5,75 @@ // 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:eight_queens/results.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:eight_queens/main.dart'; void main() { -// testWidgets('Counter increments smoke test', (WidgetTester tester) async { -// // Build our app and trigger a frame. -// await tester.pumpWidget(MyApp()); -// -// // Verify that our counter starts at 0. -// expect(find.text('0'), findsOneWidget); -// expect(find.text('1'), findsNothing); -// -// // Tap the '+' icon and trigger a frame. -// await tester.tap(find.byIcon(Icons.add)); -// await tester.pump(); -// -// // Verify that our counter has incremented. -// expect(find.text('0'), findsNothing); -// expect(find.text('1'), findsOneWidget); -// }); + group('Main Application tests', () { + testWidgets('My App has a title', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(MyApp()); + + // Find the title + expect(find.text('Eight Queens App'), findsOneWidget); + }); + + testWidgets('My App has the desired message', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(MyApp()); + + // Find the title + expect(find.text('Select a board size'), findsOneWidget); + }); + + testWidgets('My App has an usable textfield', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(MyApp()); + + // Enter a number into the textfield + await tester.enterText(find.byType(TextField), '8'); + + //Expect it was stored correctly + expect(find.text('8'),findsWidgets); + }); + + testWidgets('App pushes a new view with results', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(MyApp()); + + // Enter a number into the textfield + await tester.enterText(find.byType(TextField), '8'); + + //Tap the button to go to the next screen + await tester.tap(find.byIcon(Icons.done)); + + // Wait for it to be shown + await tester.pumpAndSettle(); + + //Expect the new page to be shown + expect(find.byType(ResultsPage),findsOneWidget); + }); + + testWidgets('App with invalid input wont show results widget', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(MyApp()); + + // Enter a number into the textfield + await tester.enterText(find.byType(TextField), '0'); + + //Tap the button to go to the next screen + await tester.tap(find.byIcon(Icons.done)); + + // Wait for it to be shown + await tester.pumpAndSettle(); + + //Expect the new page to be shown + expect(find.byType(ResultsPage),findsNothing); + }); + + + }); }