简体   繁体   中英

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.

I noticed that when I run the tests with flutter test , the first two unit tests will start at approximately the same time.

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 .

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.

As per the Flutter help document:

-j, --concurrency=<jobs> defines the number of concurrent test processes to run. This will be ignored when running integration tests. (defaults to "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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM