Search Unity

Warnings about nunit/TestRunner

Discussion in 'Editor & General Support' started by cdarklock, Apr 4, 2017.

  1. cdarklock

    cdarklock

    Joined:
    Jan 3, 2016
    Posts:
    455
    Since upgrading to Unity 5.6 / VS Community 2017, I get two warnings in VS when I compile:

    The primary reference "nunit.framework" could not be resolved because it has an indirect dependency on the framework assembly "System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v3.5,Profile=Unity Subset v3.5".

    This is accompanied by an identical warning for "Unity.TestRunner" but does not seem to cause any actual issues when running the game.

    Why does this happen and how do I fix it?
     
  2. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
  3. cdarklock

    cdarklock

    Joined:
    Jan 3, 2016
    Posts:
    455
    If I scroll far enough down that page, I get sent to this page for upgrade instructions:

    https://github.com/nunit/docs/wiki/Upgrading

    But the only thing that remotely approaches "instructions" on this page is a single line:

    "Remove references to your old version of NUnit and replace them with references to NUnit 3.0."​

    I went into the solution and found that there is a reference to Project\Library\UnityAssemblies\nunit.framework.dll in it. When I go look at the properties of this file, it is version 3.5.0.0, so it looks to me like I already have references to 3.0 and not the old version.

    Maybe the problem is that Unity does not install the proper dependencies. I've seen that before; it would normally be resolved by installing the bundled software standalone, but if I go to the "Install" page for NUnit 3.0, it tells me to open the "NuGet Package Manager" from the VS tools menu. There is no such entry in the VS tools menu. If I search for "NuGet Package Manager" in the marketplace, there is no such extension.

    The closest thing to it is a "Package Installer" which promises to install NuGet packages, but when it is added to VS it does not appear in the Tools menu and when opened from the Project context menu it has no list of available packages to install.

    I did some further searching and determined that I needed to install a "test adapter" in VS, which again I could do with a "library package manager" that doesn't exist in the Tools menu, or alternately by searching the marketplace. I searched the marketplace, and found three extensions: a test adapter, a test generator, and some templates. I selected them all, closed VS, and waited a good long time for them to install.

    This gave me the NuGet Package Manager on my Tools menu, so I followed the instructions to add both NUnit and NUnit.Console to the solution, which... has not made the warnings go away. Now I have four extensions in VS, and I don't know if I actually need them.

    Furthermore, this post implies that when I do want to add tests to my project, it may not be very well documented. I looked up TestRunner in the documentation, and it sent me to a quickstart for 2.6.4 which links to the 3.0 documentation's root page where there is no quick start.

    When I back up to the old version, I read in the intro that it "isn't a good example of Test-Driven Development." Great! So it's not going to demonstrate anything relevant, then. That will save some time... not.

    Right now, I want these warnings to go away. I did not write the code that causes them and it should not be my job to fix them. I also want some assurance that when I want to add tests to my project, the solution Unity provides for this will be sufficiently documented that I can focus on writing the tests and not mucking about with the test framework.

    I do not consider this unreasonable. What I do consider unreasonable is the amount of time I have had to waste on it for literally no meaningful progress.
     
  4. Michael-Ryan

    Michael-Ryan

    Joined:
    Apr 10, 2009
    Posts:
    184
    Both of the warnings you mentioned will go away if you change your project's API Compatibility Level to ".NET 2.0". You'll need to relaunch Visual Studio to see the results.

    You'll find that setting in the "Other Settings" section of Player Settings, which you can access via Edit | Project Settings | Player.

    This is merely a workaround. Ideally, the default ".NET 2.0 Subset" option would also work without producing the warnings.
     
    luitas and Glurth like this.