Skip to content
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

fix: wrap tests in group to fix issue #320 #321

Closed

Conversation

Giuspepe
Copy link
Contributor

@Giuspepe Giuspepe commented Mar 18, 2022

Description

This PR fixes the following issue: #320 (comment)

  • Wrap each test in the generated .test_runner.dart in a group so setUp/tearDown bodies are only run for the test declaring the bodies instead of running all setUp/tearDown bodies for all tests
Changed brick
// GENERATED CODE - DO NOT MODIFY BY HAND
// Consider adding this file to your .gitignore.

import 'package:flutter_test/flutter_test.dart';

{{#tests}}import '{{{.}}}' as {{#snakeCase}}{{{.}}}{{/snakeCase}};
{{/tests}}
void main() {
{{#tests}}  group('{{#snakeCase}}{{{.}}}{{/snakeCase}}', {{#snakeCase}}{{{.}}}{{/snakeCase}}.main);
{{/tests}}}

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@felangel
Copy link
Contributor

Hi @Giuspepe 👋
Thanks for opening a pull request!

Are you able to provide a link to a minimal reproduction sample that illustrates the problem you were encountering prior to wrapping each test in a group? Thanks! 🙏

@Giuspepe
Copy link
Contributor Author

Hey @felangel, I uploaded a minimal reproduction sample here: https://github.com/Giuspepe/very_good_cli/tree/sample/wrap-tests-in-group/test

Running the tests with dart test succeeds:

giuseppe@Giuseppes-MBP very_good_cli % dart test test --reporter expanded 
00:00 +0: test/foo_test.dart: foo
00:00 +1: test/bar_test.dart: bar
00:00 +2: All tests passed!

Running the tests with very_good test fails:

(base) giuseppe@Giuseppes-MBP very_good_cli % very_good test
Running "flutter test" in /Users/giuseppe/repos/very_good_cli...
✓ Optimizing tests (1.4s)
Invalid argument(s): Object/factory with  type int is already registered inside GetIt. 
package:get_it/get_it_impl.dart 7:18   throwIf
package:get_it/get_it_impl.dart 803:5  _GetItImplementation._register
package:get_it/get_it_impl.dart 458:5  _GetItImplementation.registerFactory
test/bar_test.dart 6:20                main.<fn>

foo /Users/giuseppe/repos/very_good_cli/test/.test_runner.dart (FAILED)
Invalid argument(s): Object/factory with  type int is already registered inside GetIt. 
package:get_it/get_it_impl.dart 7:18   throwIf
package:get_it/get_it_impl.dart 803:5  _GetItImplementation._register
package:get_it/get_it_impl.dart 458:5  _GetItImplementation.registerFactory
test/bar_test.dart 6:20                main.<fn>

bar /Users/giuseppe/repos/very_good_cli/test/.test_runner.dart (FAILED)
00:01 -2: Some tests failed.

@felangel
Copy link
Contributor

This has been addressed via #329

@felangel felangel closed this Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants