How is the execution order defined between multiple tests within matlab.uni​ttest.Test​

22 views (last 30 days)
William Hill
William Hill on 12 Oct 2017
Commented: Andy Campbell on 23 Mar 2020
Okay, I have a sequence of tests which need to be executed within a specified order. Is order guaranteed by position within the file? Or is there some other criteria for running test methods in sequence?
William Hill
William Hill on 12 Oct 2017
This is mostly a hypothetical question. While I can certainly place the unit tests in sequence under a larger test method, it would require me to add more complexity to my application. I simply want to know how the sequence is determined, and whether such an addition is truly necessary.

Sign in to comment.

Answers (1)

Andy Campbell
Andy Campbell on 16 Oct 2017

Hi William,

The order is not guaranteed by design. This is so that the tests can follow the principle of Independent Test. By prinicple, each test should be independently runnable on its own, which allwos for the tests to be easily reproducible when failures are encountered, and any subsetof a test suite can be run. It also facilitates running them in parallel.

If there were a guaranteed order of tests, then tests would begin depending on one another which would result in an inability to run them each independently. Test B would not pass without first running Test A and so forth.

If you'd like a defined order it sounds more like an integration or system test, which should be written in a single test method.

Hope that helps! Andy

Andy Campbell
Andy Campbell on 23 Mar 2020
No, there is no guarantee of the order between different TestClassSetup/TestMethodSetup/etc methods defined in a class. Obviously you can be assured that all TestClassSetup methods will execute before any TestMethodSetup, and you also have assurance that setup methods defined in a base class execute before derived (and base class teardown methods execute after derived ones). However, at the same level of class hierarchy there is no guarantee of order, and they should all be independent.

Sign in to comment.



Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!