我用的是Dart测试包:https://pub.dartlang.org/packages/test
通常,我希望在测试文件中的每个测试之前或之后运行一些函数.测试包对此有什么帮助吗?
我用的是Dart测试包:https://pub.dartlang.org/packages/test
通常,我希望在测试文件中的每个测试之前或之后运行一些函数.测试包对此有什么帮助吗?
在test()
函数前加一个setUp(() { add your code here})
.
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.
最近增加了setUpAll()
和tearDownAll()
,以便在所有测试之前和之后进行一次设置和拆除.