Jack
Jack

Reputation: 492

Rerunning groups of tests in xunit for diferent program modes

I have a program which can run in three modes, each of which have somewhat different operational logic, and a different data set.

I am adding unit testing to this project using XUnit, and would like to have a set of tests that fires once for each of the program modes.

I could do this using [InlineData()] for each test with a range of values from 1-3, and then select each mode from an array. However, the problem with this approach is that switching mode takes around 20 seconds, and I'd rather have my set of tests run once for each of my three modes, rather than changing modes each time I ran a test.

Does anyone have any suggestions for how I could call a set of tests for N different modes, each with a different data set, only switching once for each mode?

Upvotes: 1

Views: 86

Answers (1)

Ruben Bartelink
Ruben Bartelink

Reputation: 61893

Typically, one addresses sort of concern by implementing the test as a (normally private) Test Method in an abstract class, and then make concrete derived classes per configuration you're interested in using - the test will run per concrete class.

You can share state between tests in each class or across them using the relevant various xUnit mechanisms.

Upvotes: 1

Related Questions