Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Same test works in VS2015 but fails in NCrunch
Christoph
#1 Posted : Thursday, May 19, 2016 9:11:19 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/19/2016(UTC)
Posts: 3
Location: Switzerland

Was thanked: 1 time(s) in 1 post(s)
Hello NCrunch

I downloaded NCrunch today and tried it out with a simple project of mine which is published as Nuget package "SingleFile.VB.ExtString.FillIn" (which are 5 VB.NET source files containing a single test class).

When I try out that package on a VB project that runs under .NET 3.5 then the UnitTest run through the Test menu of Visual Studio 2015 community edition with update 2 succeeds and the NCrunch run of the same test class fails. In a VB project with .NET 4.0 or higher everything is fine.

Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.AreEqual failed. Expected:<Number: 12,345.68>. Actual:<Number: 12'345.68>.

The test explicitly assigns the number format and the language to the current thread as part of the test.

Any ideas why the test fails in NCrunch but succeeds as VS2015 standard UnitTest?

Steps to reproduce:
1) Create a VB-project for .NET version 3.5 called "Foo.vbproj"
2) Install Nuget package "SingleFile.VB.ExtString.FillIn" (currently of version 1.0.26)
3) Build the project and call Test/Run/All Tests
4) Double-click "ExtString_FillIn" in window "Test Explorer" (the test passed and is green) and the cursor is now at the beginning of the test method, which NCrunch dotted all red.
5) Look at window "NCrunch Tests", the same test failed.

Best regards
Chris
Remco
#2 Posted : Friday, May 20, 2016 12:05:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Chris,

Thanks for sharing this issue.

I received some inconsistent results from the code you supplied. I narrowed it down the following:

dim result = String.Format(CultureInfo.GetCultureInfo("de-CH"), "{0:0.###}", 18.45)
Console.WriteLine(result)

The above code returns a different result on some systems. On my own development machine, this returned '18.45', where on another system, it returned '18,45'.

I believe this may have something to do with the cultures that are installed on the machine being used.

Interestingly, in neither case was my result the same as yours. On my development machine, all the tests passed fine under NCrunch. On the other machine, it failed in a completely different place to where you reached the error.

The code did not compile for me under .NET 3.5.

I've inspected the parameters around the NCrunch test environment and confirmed that they are all behaving as expected. I believe this to be pass/fail behaviour dependent upon the state of the .NET framework and the environment in which the tests are being executed.

Sorry, there may not be much more I can do to help you with this problem.
Christoph
#3 Posted : Friday, May 20, 2016 9:07:28 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/19/2016(UTC)
Posts: 3
Location: Switzerland

Was thanked: 1 time(s) in 1 post(s)
Hello Remco

Yeah, that problem you got on different machines is based on an ugly story that happened over here: Some Swiss government office (not the department for information technology!) decided that our official decimal symbol is now the "," like in Germany and not the ".". Nobody took notice of that, nobody cared, our keyboard layout has and always had a dot in the numeric block etc. but Microsoft changed it to be the "," when they shipped Windows 8.0... Luckily everything was recalled and our decimal symbol remains the "." except in hand written numbers...

But back to the issue:

Take your developer machine (where the value is correctly "18.45") and install the Nuget package AFTER you changed the project to .NET 3.5 (the source code is slightly different as StringBuilder.Clear() was only introduced in .NET 4.0). Then it builds correctly and you can reproduce the behavior: In the "Test Explorer" window the test succeeds, in "NCrunch Tests" window it fails (and the code is dotted red).
Remco
#4 Posted : Friday, May 20, 2016 9:49:38 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Christoph;8747 wrote:

Yeah, that problem you got on different machines is based on an ugly story that happened over here: Some Swiss government office (not the department for information technology!) decided that our official decimal symbol is now the "," like in Germany and not the ".". Nobody took notice of that, nobody cared, our keyboard layout has and always had a dot in the numeric block etc. but Microsoft changed it to be the "," when they shipped Windows 8.0... Luckily everything was recalled and our decimal symbol remains the "." except in hand written numbers...


Interesting. It's quite common to see situations in a company where the IT department isn't consulted before major decisions are made. It's rather frightful to see this happening on a country-wide level, though far from unusual I guess.

Christoph;8747 wrote:

Take your developer machine (where the value is correctly "18.45") and install the Nuget package AFTER you changed the project to .NET 3.5 (the source code is slightly different as StringBuilder.Clear() was only introduced in .NET 4.0). Then it builds correctly and you can reproduce the behavior: In the "Test Explorer" window the test succeeds, in "NCrunch Tests" window it fails (and the code is dotted red).


Thanks, this got the code compiling .. I'm not sure why I didn't think of that at the time.

On my development machine, the test passes normally while under .NET 3.5. This is a slightly different setup to yours (VS 2015 Enterprise w/ Update 2 Windows 8.1). Though I still can't reproduce the problem, given your comment about the culture being changed in an update, I might hazard a guess as to why the behaviour here isn't consistent.

If MS reverted the ',' back to '.' in an update, then I could see this causing all kinds of chaos between different environments. When NCrunch runs tests under .NET 3.5, it will do so using a task runner .exe built to target .NET 3.5. The same pattern applies for other versions of the framework. The task runner .exe itself is essentially little more than a windows application (originally a console app actually) that accepts some data from the NCrunch engine over IPC, then proceeds to call into your test code via your chosen framework. This means that in theory, you should be able to replicate the behaviour of the NCrunch task runner by creating your own console application using the same version of the .NET framework, then calling into your test code directly.

I've observed that under my current setup VSTest is calling into the test using the same version of the core .NET assemblies as is used by the NCrunch task runner. This isn't a surprise, because the test passes in my environment. I'd be interested to know whether something in your environment (perhaps VS community?) is using a different version of the framework when calling into your code via VSTest. My theory is that the exact revision of the framework being referenced in your VSTest is somehow different to the one being used by a standard .NET 3.5 application. At the moment I'm having a hard time understanding how else such a difference in behaviour could exist unless there were bugs in the framework itself. You may wish to try checking this by starting up a couple of debug sessions (NCrunch vs VSTest), then comparing the list of loaded modules inside each of the test processes.

Regardless of whether this is a framework versioning issue or an environment related bug of some kind, I don't think there will be any functional change that can be made to NCrunch that will solve this problem. For compatibility reasons, NCrunch needs to run test code using the same version of the .NET framework that would be used for a standard .NET application. NCrunch isn't able to safely override the behaviour of low level logic within the framework itself. It may well be that the functioning of this test code will always be inconsistent depending upon the environment it's being run in. Given that the de-CH culture can behave differently on different machines, I would perhaps suggest using a different culture for your testing purposes (assuming you are interested in testing the code itself and not the environment it's being executed in).
Christoph
#5 Posted : Friday, May 20, 2016 1:37:15 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/19/2016(UTC)
Posts: 3
Location: Switzerland

Was thanked: 1 time(s) in 1 post(s)
Yeah I was also shocked when a customer of mine was calling me that an import does not work anymore after moving the application to a (at that time) new Windows 8.1 machine and, when I investigated, I found out that our decimal sign was changed... (with 8.1 came that change, not as I said before with 8.0)

I cannot really imagine that this is because of framework differences. I mean it only uses "mscorlib.dll" which is extremely well tested, and the locales are not part of that framework. Have more the idea it's because of some kind of protection of the thread, that setting the locale on the current thread is ignored for some reason (but against that theory speaks that it works now after implementing some compatibility improvements, see next paragraph).

I now improved the tests and explicitly set the decimal symbol and grouping symbol for every locale I use in the tests and now it works in both NCrunch und VS2015 directly, in .NET 3.5 and 4.x.

Strange! But wouldn't IT be boring without such constellations? ;-)

Thank you for taking your time to reproduce this issue.
1 user thanked Christoph for this useful post.
Remco on 5/20/2016(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.054 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download