Search code examples
unit-testingflutterdart

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


Solution

  • 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