-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Flutter create widget test template. #11304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Running `flutter create —with-widget-test` produces a test/widget_test.dart sample widget test.
yjbanov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but we should test that generated test passes.
| @@ -0,0 +1,44 @@ | |||
| // This is a basic Flutter widget test. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure that running flutter test on this test actually passes. Perhaps add it to https://github.com/flutter/flutter/blob/master/dev/bots/test.dart?
|
Please just make the test always be included, rather than making it optional. |
|
Fixes #4080 |
|
We should probably test the test in the same test that analyzes the output of |
|
@Hixie : would you mind taking another look? Analysis of created bits should now be correct (if a little hacky) for plugins and package projects. |
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void main() { | ||
| testWidgets('my first widget test', (WidgetTester tester) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give it a more descriptive title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Especially when we're testing something interesting!
|
|
||
| // Verifies that the widget updated the value correctly | ||
| expect(value, 0.5); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this test actually test the app that we created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. it could test that tapping on the FAB increments the counter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. I was just cribbing the contents of https://flutter.io/testing/#unit-testing to get us started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hixie : looking at improving the sample now. Are you OK with this landing and us continuing a separate PR w/ improvements? I suspect that we may want a bit of back and forth (and possibly other input). For example, should we bake a unique key into the sample app itself? Are there specific testing idioms we want to encourage?
| Future<Null> _createAndAnalyzeProject( | ||
| Directory dir, List<String> createArgs, List<String> expectedPaths, | ||
| [List<String> unexpectedPaths = const <String>[]]) async { | ||
| {List<String> unexpectedPaths = const <String>[], bool plugin = false}) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spaces around named arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| )); | ||
|
|
||
| final List<String> args = <String>[flutterToolsPath, 'analyze']; | ||
| if (target != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no braces around single-line if statement blocks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
I think we should check this in with a test that tests the app. I don't think it's valuable to have a sample test if the sample test isn't testing the app, because it'll just confuse people. The sample test would be really simple. Just pumpWidgets one of the widgets introduced in the main template, expect the counter number is 0 (and not 1), tap the FAB byType, pump, expect the new counter number is 1 (and not 0). Shouldn't need any changes to the main app. |
|
@Hixie : here's a quick stab at more relevant test content. Plenty of room for improvement but it's a start... Input welcome! |
| void main() { | ||
| testWidgets('Counter increments smoke test', (WidgetTester tester) async { | ||
| // Build our app and trigger a frame. | ||
| await tester.pumpWidget( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i would put this on one line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
This reverts commit f0c2d5e.
Adds a
--with-widget-testoption toflutter createthat produces a sample widget test intest/widget_test.dart.We'll likely default to using this option in the IDE (flutter/flutter-intellij#1171). Alternatively, we could default this to true in
create.dart(which I'm open to).Template content was derived from https://flutter.io/testing/#unit-testing. Word and content-smithing welcome. 👍
@LarkAscending @Hixie @yjbanov