I'm using the Dart test package: https://pub.dartlang.org/packages/test
Often, I want to run some function before or after each tests in my test file. Does the test package provide something for this?
I'm using the Dart test package: https://pub.dartlang.org/packages/test
Often, I want to run some function before or after each tests in my test file. Does the test package provide something for this?
add a
setUp(() { add your code here})before yourtest()function. There is also atearDown()which is run after each test.If you add the setUp function at top level in main it is run for every test, if you put it inside a group it is run for every test in that group. You can have setUp/tearDown on more than one level at the same time.
tearDownis executed in any case (likefinally) no matter if the test fails or succeeds.Recently
setUpAll()andtearDownAll()was added to do some set up and tear down once before and after all tests.