-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Crdzbird/unit test flutter #259
Conversation
Widget Test Unit Test Integrity Test
Awesome to have some tests! |
@@ -84,6 +84,43 @@ Once the required tools are installed and the lfs are downloaded, open the proje | |||
- Edit the run config and add on the flavor option prod | |||
|
|||
|
|||
## Unit Tests | |||
|
|||
To run the unit test you need to input the following setup. |
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.
Is there a way to do this from the command 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.
yep. an example would be:
flutter run test/catcher_test.dart --coverage or
flutter run test/catcher_test.dart
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.
if you wish to run everything just replace the catcher_test with an * and it should run everything
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.
Thanks! Could you add that to the readme please?
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.
Sure.
README.md
Outdated
|
||
1. On your `terminal` check if you have installed: `lcov` if not then install. | ||
2. Go to on your terminal `android-lantern/coverage` and type: `genhtml coverage/lcov.info -o coverage/html` that will generate a nice html file with the code coverage of all your files. | ||
#### NOTE: Please avoid to upload the generated files from coverage, this is because the numerous files that are 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.
Can you please add the necessary directories/files to .gitignore
?
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.
Sure, im gonna omit the coverage
and genhtml
coverage/lcov.info
Outdated
@@ -0,0 +1,4857 @@ | |||
SF:lib/config/catcher_setup.dart |
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.
Does this need to be checked in?
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.
actually... that is also needed to be omitted, im gonna add it to the .gitignore as suggested
I can't run the test from the command line
|
|
I notice that I forget to update one test |
@@ -32,6 +32,10 @@ app.iml | |||
# is commented out by default. | |||
.vscode/ | |||
|
|||
coverage | |||
coverage/html/ | |||
coverage/lcov.info |
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.
Added coverage folder to .gitignore
### Run Independent Tests | ||
|
||
On your terminal go to the root of the project and type: | ||
`flutter test test/my_folder_test.dart` |
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.
Example of how to run flutter unit test without coverage
`flutter test test/my_folder_test.dart` | ||
|
||
in case that you need the code coverage just add the following argument. | ||
`flutter test --coverage test/my_folder_test.dart` |
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.
Example of how to run flutter unit test with coverage
If you wanna visualize the current percentage of code coverage you need to do the following steps. | ||
|
||
1. On your `terminal` check if you have installed: `lcov` if not then install. | ||
2. Go to on your terminal `android-lantern/coverage` and type: `genhtml coverage/lcov.info -o coverage/html` that will generate a nice html file with the code coverage of all your files. |
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.
Explanation about how to generate a informative graph about the percentage of code coverage on the project.
@@ -109,6 +109,7 @@ dev_dependencies: | |||
sdk: flutter | |||
|
|||
test: ^1.15.7 | |||
mockito: ^5.0.12 |
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.
Mockit is used in order to be capable to emulated some specific code ex: auto_route
Thanks! If I run all tests, the catcher_test fails. I don't think that's new to this branch, but since you're in here, would you mind taking a look please?
|
Interesting it seems that the error is not actually on the catcher but rather on base_screen, will take a look on that |
}), | ||
)); | ||
await tester.pumpAndSettle(); | ||
expect(find.byType(HomePage), findsOneWidget); |
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.
The error was due to the widget still wasn't settle and also the multi provider wasn't inside the scope
@oxtoacart All tests should be working, also for any navigation test is preferable to use the |
Awesome @Crdzbird ! I love the documentation. |
The test at the time has a tiny percentage of code coverage, hope that this will increase at their respective moment, also added documentation about how to run and generate the visual graph.