Home > Software design >  What local settings in visual studio or windows are requried for NUnit to evaluate whitespace in cur
What local settings in visual studio or windows are requried for NUnit to evaluate whitespace in cur

Time:08-05

When running an NUnit unit test, the test fails due to whitespace mismatch between actual and expected results generated during a call to decimal.ToString(). This appears to be a local issue.

What settings can I change in either Visual Studio 2022 (Community) or Windows 11 to get the expected result and the actual result to match?

Here's a simplified version of what's being tested:

public void Test()
{
    decimal d = 1234;
    CultureInfo culture = new CultureInfo("fr");
    culture.NumberFormat.CurrencySymbol = "€";
    Assert.AreEqual("1 234,00 €", d.ToString("C2", culture));
}

Note: 1234, "fr", "€", and "1 234,00" are being passed in to the test as a [TestCase].

Here's a screenshot of the failed test:

screenshot of test explorer showing white space differences in test result

Notice: a) the difference in white space after the 1, and b) the white space before the is the same for both expected and actual!

This only happens on my computer! Deployment pipelines and other people's local environments are passing these tests.

How can I test which value is being handled incorrectly, and/or what settings in VS or my OS can I adjust to get the whitespaces to match?

Note: I have not touched this code, this is as-is from the repository and the test passes in other environments, so the problem has to be with my setup and not with the writing of the test or the code being tested.

CodePudding user response:

It appears this is a result of how Windows 11 handles the group separator for the french language and there is no setting to change it.

Supporting evidence:

  • Related