JeffH
JeffH

Reputation: 10482

With mstest, can I run my unit test suite against each of my supported languages?

We use .resx files to internationalize our app to several languages. Our automated unit tests are in their own assembly, and we run mstest on that project from the command line from within our CI (Jenkins) like this:

mstest.exe /testcontainer:unittests.dll /category:"!TemporaryExclude" /resultsfile:UnitTests.trx

We've found cases where particular unit tests would fail if run on a machine set to one of our non-English supported cultures. We'd like to have our CI run the unit tests against each culture, including the current en-us one. This must be a problem that other people have run into, but I haven't found anything on it.

Is there a way to run mstest against a specific culture? I didn't see anything in the command-line docs for mstest.exe

I know that I could specify the Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture in my tests, but I don't want devs on our team to have to copy-paste duplicates of their tests, one per culture. It would be extra work for them and having duplicates different only by culture would be hard to maintain and prone to errors.

I wondered about deriving a class from TestMethodAttribute and having it cycle through all my language resource DLLs, running the test code once for each, but Visual Studio tells me:

Error 2 'ClassToExtendTestMethodAttribute': cannot derive from sealed type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute'

Same for TestClassAttribute.

Upvotes: 5

Views: 1394

Answers (1)

henginy
henginy

Reputation: 2071

One idea might be to read the culture from a config file in the TestInitialize method in order to use with Thread.CurrentThread.CurrentCulture, and putting this method into a base unit test class (that all other test classes should be deriving from). If this does the trick, you can call mstest from a batch file in a loop and change the config file (from "en-us" to "fr-FR" for example) after every step.

Alternatively, here is a pointer to a "Unit Test Extensibility Sample" which I haven't used, but might help you.

Upvotes: 3

Related Questions