NUnit, multi-crop testing

Using NUnit I want to run all the tests in a specific project against multiple cultures.

The project considers parsing data that should be culturally neutral; to ensure this, I would like to run each test against several cultures.

I have a current solution

public abstract class FooTests { /* tests go here */ } [TestFixture, SetCulture ("en-GB")] public class FooTestsEN : FooTests {} [TestFixture, SetCulture ("pl-PL")] public class FooTestsPL : FooTests {} 

Ideally, I don't need to create these classes and instead use something like:

 [assembly: SetCulture ("en-GB")] [assembly: SetCulture ("pl-PL")] 
+4
source share
3 answers

Unfortunately, this is now impossible, but planned for the future.

You can also do this.

 public class AllCultureTests { private TestSomething() {...} [Test] [SetCulture("pl-PL")] public void ShouldDoSomethingInPoland() { TestSomething(); } } 

Perhaps something you would prefer?

+3
source

NUnit SetCultureAttribute applies one culture to the test, several cultures are not supported (yet).

You can get around this using TestCaseAttribute with language codes and manually adjust the culture:

  [Test] [TestCase("de-DE")] [TestCase("en-US")] [TestCase("da-DK")] public void YourTest(string cultureName) { var culture = CultureInfo.GetCultureInfo(cultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; var date = new DateTime(2012, 10, 14); string sut = date.ToString("dd/MM/yyyy"); Assert.That(sut, Is.EqualTo("14/10/2012")); } 

Please note that this unit test does not work for de and da - testing for different cultures is really important :)

+2
source

If you don't mind switching, MbUnit has had this feature for almost five years now .

You can apply the MultipleCulture attribute at the test, build, and build levels.

+1
source

All Articles