12

I have the following simple test case:

var uri = new Uri("http://foo.com/bar%2Fbaz");
Assert.AreEqual("http://foo.com/bar%2Fbaz", uri.AbsoluteUri);

This test fails on .NET 4 but passes on .NET 4.5, I can test this using ReSharper test runner which provides a handy CLR selection menu.

But if I run this test using nunit console runner like the following:

nunit-console.exe /framework:4.5 "C:\Data\Projects\UriTest\bin\Debug\UriTest.dll"

My tests get failed. I have even modified nunit-console.exe.config and added this:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

and after adding this, I have started to get this output from runner:

Runtime Environment -
   OS Version: Microsoft Windows NT 6.2.9200.0
  CLR Version: 4.0.30319.34209 ( Net 4.5 )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: v4.5

But still my test fails. Any idea why this happens?

huseyint
  • 14,953
  • 15
  • 56
  • 78

2 Answers2

8

After taking a look more deeply at the issue, here's the information I gathered from different forums.

First, it should detect the runtime automatically. If it doesn't (which seems to be your case), you can always force the framework using the proper runtime by using the /framework command option.

What you have in the nunit-console.exe.config forces the NUnit runner to use the specified runtime. If your assembly is in a different .NET version, NUnit will run them in a separate process to force the framework version.

See the documentation for NUnit 2.6.2.

What you have in your command line shouldn't be /framework:4.5 but rather /framework:net-4.5

The next step would be to take a look at your test and see if there's something specific that makes it fail.

Please comment some more for more info.

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
  • Thanks for the answer but this doesn't seem to work. First, clr.bat is not shipped with NUnit 2.6.3 and the new documentation doesn't mention that. Also, the old docs say "Note: If you use a section in the config file, it takes precedence over this option." which is practically what I have done with .exe.config file. – huseyint Nov 19 '14 at 14:38
  • 1
    Still fails with /framework:net-4.5 switch. You can reproduce this easily: 1. Create a DLL project with this [Test] using .NET 4.5.2 2. Build it 3. Run it through nunit-console (or nunit GUI for that matter) – huseyint Nov 19 '14 at 18:06
  • 1
    If you have trouble using the framework command line parameter for nunit-console, try using `/framework=net-4.5` with an equal (=) instead of colon (:) between the parameter name and value. – park896 Nov 10 '15 at 05:13
  • I've got the same issue as OP, using /framework even shows v4.5 as the chosen runtime in nunit-console but the test still fails because its not really using that framework from what I can tell. – Andrew May 10 '17 at 01:49
0

In .NET 4.0 Framework there was a bug regarding encoding slash values. You could check out description here. In 4.5 it was fixed to make result RFC-3986 compliant. So, that's why you have the different behaviour for 4.0 & 4.5.

alekseevi15
  • 1,732
  • 2
  • 16
  • 20
  • Yep, I am aware of the change, the problem I have is with the nunit test runners which seems to work with .NET 4 even if I try to force them to use .NET 4.5 – huseyint Nov 19 '14 at 14:42
  • @huseyint, are you building your solution against 4.5 before running tests? – alekseevi15 Nov 19 '14 at 14:48
  • Yes, my solution is build against .NET 4.5.2 specifically. – huseyint Nov 19 '14 at 15:07
  • May be this cmd example will help you(to build solution against specified version and then run nunit-console): [link](https://github.com/SmartElk/Antler/blob/master/build/build.cmd) – alekseevi15 Nov 19 '14 at 15:08