Controlling Execution Order of Unit Tests in Visual Studio

Controlling execution order of unit tests in Visual Studio

Merge your tests into one giant test will work. To make the test method more readable, you can do something like

[TestMethod]
public void MyIntegratonTestLikeUnitTest()
{
AssertScenarioA();

AssertScenarioB();

....
}

private void AssertScenarioA()
{
// Assert
}

private void AssertScenarioB()
{
// Assert
}

Actually the issue you have suggests you probably should improve the testability of the implementation.

Cmocka - should we all be creating one executable per test for isolating static variables?

Yes, if you have a static variable in the tested object, you need to compile separated tests if they expect a "fresh" test object.

I would do this anyway, each test in a separated executable, since you have a Singleton in your test object.

This is a fine example why the Singleton pattern is an anti-pattern today. It is hard to test.

Is there a way to run unit tests sequentially with MSTests?

There is the notion of an "Ordered Test" in which you can list tests in sequence. It is more geared towards ensuring a certain sequential order, but I can't see how that would be possible if B doesn't wait for A to complete.

Apart from that, it is unfortunate that your tests interfere with each other. There are Setup / TearDown methods that can be used per test such that it may after all be possible to isolate the tests from each other.



Related Topics



Leave a reply



Submit