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

17 Ansichten (letzte 30 Tage)
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?
  2 Kommentare
Steven Lord
Steven Lord am 12 Okt. 2017
Can you say a little more about what you're testing that requires your tests to be executed in a specific order? It's possible you have written an integration test in several pieces, when ideally you'd want to have those pieces each be independent unit tests and create a new larger test method that holds your entire integration test.
William Hill
William Hill am 12 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Andy Campbell
Andy Campbell am 16 Okt. 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

  4 Kommentare
Seungbum Koo
Seungbum Koo am 23 Mär. 2020
How about the test setup? Will the class/method setup functions be called in the order they appear?
Andy Campbell
Andy Campbell am 23 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Write Unit Tests finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by