I have a unit-test that relies on a specific culture.
In FixtureSetup, I set both Thread.CurrentThread.CurrentCulture
and Thread.CurrentThread.CurrentUICulture
to the desired value (en-US).
When I run the test from Resharper, it passes.
When I run the test from TeamCity (using the runner "NUnit 2.4.6"), the test fails, because
CurrentCulture
is cs-CZ
(the culture of my OS). However CurrentUICulture
is still en-US
.
You can force a specific culture for running your tests in your current thread System.Threading.Thread.CurrentThread
// set CurrentCulture to Invariant
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
// set UI culture to invariant
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
You can also use CultureInfo.GetCultureInfo
to provide the culture you want to use. This can be down in the SetUp
part of your tests.
Remember to restore the culture to the previous one in your TearDown
to ensure isolation
[TestFixture]
class MyTest {
CultureInfo savedCulture;
[SetUp]
public void SetUp() {
savedCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
}
[TearDown]
public void TearDown() {
Thread.CurrentThread.CurrentCulture = savedCulture;
}
}
This is exactly what I have done. It works when running my unit-tests in Resharper, it doesn't when I run them in TeamCity.
How do you run nUnit in TeamCity ?
Have you tried using the
[SetCulture("en-US")]
attribute ? http://www.nunit.org/index.php?p=setCulture&r=2.5.9have you tried to define your AssemblyCulture in the
AssemblyInfo.cs
?[assembly: AssemblyCulture("en-US")]