简体   繁体   English

依次运行 Flutter Package 单元测试

[英]Run Flutter Package unit tests serially one by one

I'm writing a bunch of unit tests with an HTTP client in them, for a custom Flutter package.我正在编写一堆带有 HTTP 客户端的单元测试,用于自定义 Flutter package。

I noticed that when I run the tests with flutter test , the first two unit tests will start at approximately the same time.我注意到,当我使用flutter test运行测试时,前两个单元测试将几乎同时开始。

This is not something I want.这不是我想要的。 Because the unit tests are supposed to write some data, and at the start of every unit test the data is reset.因为单元测试应该写入一些数据,并且在每个单元测试开始时数据都会被重置。 That way every test starts off with the same data.这样,每个测试都从相同的数据开始。

But since there are two tests running at the same time, they both access the same file and corrupt it or not get access to it with FileSystemException: lock failed .但是由于同时运行了两个测试,它们都访问同一个文件并损坏它或无法访问它FileSystemException: lock failed

Is there any way to force the tests to run one by one, instead of multiple at once?有没有办法强制测试一个接一个地运行,而不是一次运行多个? I tried putting them in separate files, but that did not work.我尝试将它们放在单独的文件中,但这不起作用。

Thanks谢谢

By default, the flutter test command executes the tests concurrently, but you can specify the concurrency using -j, --concurrency=<jobs> in the flutter test command.默认情况下, flutter test命令并发执行测试,但您可以在 flutter 测试命令中使用-j, --concurrency=<jobs>指定并发。

As per the Flutter help document:根据 Flutter 帮助文档:

-j, --concurrency=<jobs> defines the number of concurrent test processes to run. -j, --concurrency=<jobs>定义要运行的并发测试进程的数量。 This will be ignored when running integration tests.运行集成测试时,这将被忽略。 (defaults to "14") (默认为“14”)

execute the below command to run all tests one by one执行以下命令以一一运行所有测试

flutter test -j, --concurrency=1

execute the below command to run all tests one by one with coverage,执行以下命令以覆盖范围一一运行所有测试,

flutter test --coverage -j, --concurrency=1

If you have several tests that are related to one another, combine them using the group function provided by the test package.如果您有多个相互关联的测试,请使用测试 package 提供的组 function 组合它们。

Please check https://flutter.dev/docs/cookbook/testing/unit/introduction#5-combine-multiple-tests-in-a-group请检查https://flutter.dev/docs/cookbook/testing/unit/introduction#5-combine-multiple-tests-in-a-group

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XUnit - 串行运行测试 - XUnit - run tests serially 多个单元测试项目—运行所有测试,但一次运行一个项目 - Multiple Unit Testing Projects — Run all tests, but one project at a time 使用Ruby Test Unit在一个脚本中并行运行多个测试 - Run multiple tests in one script in parallel using Ruby Test Unit 如何在 Android Studio 中一键运行所有(单元和检测)测试 - how to run all (unit and instrumented) tests with one click in Android Studio 串行执行单元测试(而不是并行) - Execute unit tests serially (rather than in parallel) 如果一次运行一个单元测试则传递正常,如果运行“解决方案中的所有测试”,则为FileLoadException - Unit Tests pass fine if run one at a time, FileLoadException if run “All Tests in Solution” 一种主要方法的单元测试 - Unit tests for one main method 分别运行时,三个单元测试通过,而一起运行时,只有一个通过 - Three Unit tests pass when run separately, only one passes when run together Gradle 测试单元测试 - 运行除一个或几个之外的所有 - 命令行 - Gradle test Unit tests - Run all except one or few - Command line C# Visual Studio 单元测试不再在一个存储库中运行,但在另一个存储库中运行:相同的服务应用程序代码 - C# Visual Studio Unit Tests no Longer run in one repo but does in the other: Same Service Application code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM