标签: dart-test

Flutter/Dart 缓慢的单元测试:每个文件需要 >4 秒才能开始运行

我的一个包含 7 个空测试的测试文件需要5 秒多的时间才能开始运行。我flutter test在 VS Code 中使用了这两种方法以及 Dart 测试运行器,它们花费的时间大约相同。

我的整个测试套件包含约 150 个测试,需要30 秒以上才能完成,因为每个测试文件需要 3-7 秒才能开始运行。

launch.json(用于 Dart 测试运行程序)
    {
      "name": "Dart: Run all tests",
      "type": "dart",
      "request": "launch",
      "program": "./test/"
    },
Run Code Online (Sandbox Code Playgroud)

定时测试运行:

00:05 +1 -7: Some tests failed.
real    0m9.532s
user    0m0.075s
sys     0m0.138s
Run Code Online (Sandbox Code Playgroud)

我正在使用嵌套组块,但我不认为这会导致如此巨大的延迟,从而使 TDD 极其缓慢

代码示例部分
00:05 +1 -7: Some tests failed.
real    0m9.532s
user    0m0.075s
sys     0m0.138s
Run Code Online (Sandbox Code Playgroud)

我什至尝试过分别测试和组合测试两个空的示例测试文件(参见下面的代码),单独运行都需要 4 秒以上的时间。如果我将两个测试文件合并为一个文件,则执行时间几乎与仅一个测试相同。

问题似乎在于启动每个测试文件,而不是测试本身。

测试

test_test_1.dart
void main() {
  group('AuthCubit:', () …
Run Code Online (Sandbox Code Playgroud)

optimization unit-testing execution-time flutter-test dart-test

5
推荐指数
1
解决办法
711
查看次数