1

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?

2
  • 1
    have a base type and 3x concrete versions is the normal way Commented Feb 14, 2019 at 7:40
  • 1
    Thanks Ruben, I have ended up using inheritance as you suggested. If you put as the answer, I'll accept Commented Feb 14, 2019 at 20:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.