locked
Unit testing localized resources RRS feed

  • Question

  • I have a seperate class library that handles the localization of all of my strings so I can centrally manage them. I also created a series of unit tests (1 for each supported language) that tests retrieving a known string and compares it against the expected value. If I run them using the built in MSTest tools (and on the build server), they all fail (always returns the English string instead of the localized string).

    If I run the application, setting the CurrentCulture & CurrentUICulture to a supported language, everything is translated properly. If I run the unit tests using the Resharper Unit Test Runner, all the tests pass (debugging the tests shows them getting the proper strings back).

    My Unit Test looks like this:

    /// <summary>
    /// Tests that <see cref="TranslatedStrings"/> returns the proper
    /// string for Portuguese.
    /// </summary>
    [TestMethod]
    public void StaticPropertyReturnsPortugueseString()
    {
    	// Assign
    	var culture = new CultureInfo( "pt-BR" );
    
    	// Act
    	SetCulture( culture );
    	var actual = TranslatedStrings.SDE_COPYRIGHT;
    
    	// Assert
    	Assert.AreEqual( ptBR, actual, "String should match the 'pt-BR' version" );
    }
    
    /// <summary>Portuguese (Brazillian)</summary>
    const string ptBR = @"Copyright © {0}. Todos os direitos reservados.";
    

    What am I doing wrong? I'm sure it is a setting in Visual Studio, but I can't seem to find the answer.

    Wednesday, July 27, 2011 7:27 PM

All replies

  • To understand it better, can you please share: -

     

    1. How does SetCulture method in the above code set the culture?

    2. How does the TranslatedStrings.SDE.. get that culture?

    3. Are you using .net ResourceManager in the TranslatedStrings?

    4. Are the language resources present in different satellite dlls? If yes, Have you enabled deployment of satellite assemblies (deploySatelliteAssemblies = true) in the test settings?

       <Deployment deploySatelliteAssemblies="true"/>

     Regards

    Aseem Bansal

    Friday, July 29, 2011 4:38 AM
  • Anyone find an answer for this?
    Thursday, December 1, 2011 4:44 PM
  • Hi.

    Check this post which worked for me in similar case.

    http://social.msdn.microsoft.com/Forums/en/vststest/thread/28aed103-e70d-442d-9b18-7eebcabb65be

     

    BR, Trainee

    Tuesday, January 24, 2012 3:37 PM