NUnit not picking up .net Framework Version

Amanda K's Avatar

Amanda K

20 Feb, 2015 05:48 PM

We're trying out AppVeyor to be our CI solution for a large .NET project. We target .NET 4.5.1 and use NUnit, and the build works perfectly and the tests are discovered correctly. However, the nunit test runner consistently targets .NET 3.5 rather than 4.5, causing a couple of tests specific to 4.5 functionality to fail.

We've tried a couple approaches to resolve this issue, including a build script similar to: "nunit-console C:\projects\optirtcazure-bju5m\OptiRTC.APIHelpers.Tests\bin\Debug\OptiRTC.APIHelpers.Tests.dll /framework:net-4.5", which targets the specific project we have with the tests that fail in < 4.5.

Two questions: how can we get the nunit test runner to use the 4.5 framework, and can we do that while still having our tests autodiscoverable (we have many test projects, so this is absolutely necessary for us.)

  1. Support Staff 1 Posted by Feodor Fitsner on 20 Feb, 2015 06:02 PM

    Feodor Fitsner's Avatar

    Hi Amanda,

    So, did adding /framework:net-4.5 work?

  2. 2 Posted by Amanda Kabak on 20 Feb, 2015 06:04 PM

    Amanda Kabak's Avatar
  3. Support Staff 3 Posted by Feodor Fitsner on 20 Feb, 2015 06:12 PM

    Feodor Fitsner's Avatar

    OK, how do you manage to run that locally?

  4. 4 Posted by Amanda Kabak on 20 Feb, 2015 06:16 PM

    Amanda Kabak's Avatar

    We run it through the NUnit plug in visual studio. We tried to using the vs
    test runner on AppVeyor, but it didn't discover our tests in the project we
    specified.

  5. Support Staff 5 Posted by Feodor Fitsner on 20 Feb, 2015 06:24 PM

    Feodor Fitsner's Avatar

    OK, I'm going to create a simple test project targeting 4.5.1 and see how it gets run by NUnit.

  6. Support Staff 6 Posted by Feodor Fitsner on 20 Feb, 2015 06:55 PM

    Feodor Fitsner's Avatar

    Would you recommend a simple .NET 4.5-specific code that fails if run under 3.5?

  7. 7 Posted by Amanda Kabak on 20 Feb, 2015 07:07 PM

    Amanda Kabak's Avatar

    The ones that fail in AppVeyor are specifically related to the same issue
    that was reported here (with xUnit):
    http://help.appveyor.com/discussions/problems/996-unit-tests-all-work-on-my-dev-machine-but-some-fail-in-appveyor
    .

    Some code that reproduces the issue (fails in < 4.5) is:

    string expected = "%24skiptoken=1000&%24top=200";
    Uri uri = new Uri("
    https://data.test.com:81/api/project/?%24skiptoken=1000&%24top=200");
    uri.ToString().Contains(expected); //returns true in 4.5 and when run
    locally; false in < 4.5 and when run on appveyor

  8. Support Staff 8 Posted by Feodor Fitsner on 20 Feb, 2015 07:18 PM

    Feodor Fitsner's Avatar

    Seems formatting was eaten.

    So, the following test should pass locally?

            [Test]
            public void Test_Uri()
            {
                string expected = "%24skiptoken=1000&%24top=200"; 
                Uri uri = new Uri("https://data.test.com:81/api/project/?%24skiptoken=1000&%24top=200");
                Assert.IsTrue(uri.ToString().Contains(expected));
            }
    
  9. 9 Posted by Amanda Kabak on 20 Feb, 2015 07:27 PM

    Amanda Kabak's Avatar

    Yes, exactly.

  10. Support Staff 10 Posted by Feodor Fitsner on 20 Feb, 2015 07:52 PM

    Feodor Fitsner's Avatar

    Well, it doesn't work locally:

    C:\Projects\GitHub\nunit-config-test\NUnitConfigTests\bin\Debug>nunit-console NUnitConfigTests.dll /framework:net-4.5
    NUnit-Console version 2.6.3.13283
    Copyright (C) 2002-2012 Charlie Poole.
    Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
    Copyright (C) 2000-2002 Philip Craig.
    All Rights Reserved.
    
    Runtime Environment -
       OS Version: Microsoft Windows NT 6.2.9200.0
      CLR Version: 2.0.50727.8009 ( Net 3.5 )
    
    ProcessModel: Default    DomainUsage: Single
    Execution Runtime: net-4.5
    ...expected: %24skiptoken=1000&%24top=200
    uri.ToString(): https://data.test.com:81/api/project/?$skiptoken=1000&$top=200
    F
    Tests run: 3, Errors: 0, Failures: 1, Inconclusive: 0, Time: 0.249380701100847 seconds
      Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
    
    Errors and Failures:
    1) Test Failure : NUnitConfigTests.MyTests.Test_Uri
         Expected: True
      But was:  False
    
    at NUnitConfigTests.MyTests.Test_Uri() in c:\Projects\GitHub\nunit-config-test\NUnitConfigTests\MyTests.cs:line 40
    

    Test:

            [Test]
            public void Test_Uri()
            {
                string expected = "%24skiptoken=1000&%24top=200"; 
                Uri uri = new Uri("https://data.test.com:81/api/project/?%24skiptoken=1000&%24top=200");
                Console.WriteLine("expected: " + expected);
                Console.WriteLine("uri.ToString(): " + uri.ToString());
                Assert.IsTrue(uri.ToString().Contains(expected));
            }
    
  11. 11 Posted by Amanda Kabak on 20 Feb, 2015 07:55 PM

    Amanda Kabak's Avatar

    I took the test code, put it in a visual studio class and ran it within
    Visual Studio 2013, and it passes. In the results you sent along, I see 3.5
    specified in the NUnit runtime version:

    Runtime Environment -
       OS Version: Microsoft Windows NT 6.2.9200.0
      CLR Version: 2.0.50727.8009 ( Net 3.5 )

  12. Support Staff 12 Posted by Feodor Fitsner on 20 Feb, 2015 08:10 PM

    Feodor Fitsner's Avatar

    Yeah, but then it shows correct "Execution runtime: net-4.5", no?

    -Feodor

  13. 13 Posted by Amanda Kabak on 20 Feb, 2015 08:12 PM

    Amanda Kabak's Avatar

    It does, but I don't think it's using it given the CLR version above and
    the test failing. Again, that test passes when I run it within my local
    visual studio.

  14. Support Staff 14 Posted by Feodor Fitsner on 20 Feb, 2015 08:30 PM

    Feodor Fitsner's Avatar

    Looks like your case: http://stackoverflow.com/questions/27019061/forcing-nunit-console-runner-to-use-clr-4-5

    Too bad there's no solution yet.

    -Feodor

  15. 15 Posted by Amanda Kabak on 20 Feb, 2015 08:42 PM

    Amanda Kabak's Avatar

    Ah. Hm. Well, we do still want to use appveyor. Do you have any suggestions
    as to how we can get this to work?

  16. Support Staff 16 Posted by Feodor Fitsner on 20 Feb, 2015 09:54 PM

    Feodor Fitsner's Avatar

    OK, more information on the problem: https://github.com/nunit/nunit/issues/244
    ...and the issue it started from: https://github.com/nunit/nunit/issues/237

    Should be "fixed" like in beta 1 of nunit 3.0.

    I would just comment/ignore/skip that test to make it work with nunit-console.

  17. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 01:54 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac