Running NUnit 3 tests under multiple cultures

241 Views Asked by At

Much like this question I have a need to run all my NUnit tests in different cultures. I was hoping that there would be an attribute that allows me to specify cultures and the tests would be run in each culture in turn.

It seems there is a documented attribute detailed here which allows you to set the culture that an NUnit test runs under, however it does not allow the setting of multiple cultures.

In the answer to the linked question and several other resources found (such as here and here) which relate to NUnit 2, this feature was a planned improvement for NUnit 3.

As I cannot find evidence that this was implemented, can anyone answer this question please...

Is there a way to take an existing suite of NUnit 3 test cases and automatically run them in more than one culture in a tidy format?

I imagine I could write an application script that runs them outside of the IDE but that adds extra overhead.

I also don't relish the idea of copying and pasting the tests simply changing the "SetCulture" attribute each time (in the same vain I dont want to have to manually change this on an existing fixture before each run)

1

There are 1 best solutions below

0
On

There's nothing currently built-in to NUnit to do this that I'm aware of, although it's an idea that's been floated a couple of times. (e.g. introducing a --set-culture flag for the console runner.)

As a workaround, the SetCulture attribute can be applied at assembly level - so you could potentially have two different assembly-level SetCulture attributes under compilation symbols, and then build your test assembly twice - once for each culture. e.g.

#if US_CULTURE
[assembly: SetCulture("en-US")]
#elif UK_CULTURE
[assembly: SetCulture("en-GB")]
#endif