Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart - How run a function after or before each test?

Tags:

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?

like image 410
Kasper Avatar asked Oct 08 '15 13:10

Kasper


People also ask

How do you skip the test in flutter?

To skip a test suite, put a @Skip annotation at the top of the file: @Skip('currently failing (see issue 1234)') import 'package:test/test.

What is integration testing in flutter?

Integration tests in Flutter are written using the integration test package, provided by the SDK. This is Flutter's version of Selenium WebDriver (generic web), Protractor (Angular), Espresso (Android), or Earl Gray (iOS). The package internally uses flutter driver to drive the test on a device.


1 Answers

add a setUp(() { add your code here}) before your test() function. There is also a tearDown() 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.
tearDown is executed in any case (like finally) no matter if the test fails or succeeds.

Recently setUpAll() and tearDownAll() was added to do some set up and tear down once before and after all tests.

like image 84
Günter Zöchbauer Avatar answered Oct 15 '22 22:10

Günter Zöchbauer