How to write multiple unittests in dart in multiple files? -


i writing dart library , want have unittested. created directory test , want put tests in here. because going have lot of tests, want have them separated multiple files. questions is, dart convention, how that. want have tests run all, however, want able run 1 file of tests.

what suggestions?

it common separate tests multiple files. including example of how can that.

imagine have 2 files tests, foo_test.dart, bar_test.dart contain tests program. foo_test.dart this:

library foo_test;  import 'package:unittest/unittest.dart';  void main() {   test('foo test', () {     expect("foo".length, equals(3));   }); } 

and bar_test.dart this:

library bar_test;  import 'package:unittest/unittest.dart';  void main() {   test('bar test', () {     expect("bar".length, equals(3));   }); } 

you run either file, , test contained in file execute.

the, create all_tests.dart file import tests foo_test.dart , bar_test.dart. here all_tests.dart like:

import 'foo_test.dart' foo_test; import 'bar_test.dart' bar_test;  void main() {   foo_test.main();   bar_test.main(); } 

if executed all_tests.dart, both tests foo_test.dart , bar_test.dart execute.

one thing note: work, need declare foo_test.dart , bar_test.dart libraries (see first line of each file). then, in all_tests.dart, can use import syntax fetch contents of declared libraries.

this how organize of tests.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -