[英]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.