Why aren't resx cultures found in unit tests?

I have built-in string resources in my .NET 4.0 project: Strings.resx and Strings.de.resx.

In the production code , the correct localized strings are retrieved, depending on the value of Strings.Culture:

Strings.Culture = new Culture("de"); string deString = Strings.Welcome; // 'Willkommen' Strings.Culture = new Culture("en"); string enString = Strings.Welcome; // 'Welcome' 

But in my unit test code (using MSTest), the strings from "Strings.de.resx" never return - I only get strings from Strings.resx, regardless of whether the values ​​are Strings.Culture or Threads.CurrentThread.CultureUICulture .

Does anyone help?

+7
source share
1 answer

Ok, I was able to reproduce this problem. First of all, try disabling the deployment. Go to the "local.testsettings" section and uncheck "Deployment β†’ Enable Deployment". When this flag is set, VS does not seem to deploy satellite assemblies for me. If you need a deployment item, use DeploymentItemAttribute:

 [DeploymentItem( @".\YourProject\bin\Debug\de\YourProject.resources.dll", @".\de\")] 

or use the same Deployment tab to select the appropriate satellite assemblies.

+7
source

All Articles