Saturday, November 21, 2015

Fixing an NUnit Version Mismatch

Sometimes demos don't always go according to plan.

For those of you who were at Live! 360 this past week, I had a little trouble when I was showing how "easy" it is to get NUnit working in Visual Studio. Normally it is easy -- in fact, it's just as easy as this: Integrating NUnit into the Visual Studio Test Explorer.

But these steps did not work for me this past Wednesday. I added both NuGet packages, but the tests did not show up in the test explorer. Fortunately, I had a working solution that I prepared earlier, so we were able to continue with the demo.

The answer to the problem turned out to be pretty simple, but it wasn't something I could troubleshoot on the fly.

[Update 3/4/2016: A demonstration of installing NUnit in Visual Studio 2015 (including dealing with the current version mismatch) is available by watching a few minutes of this TDD video: TDD Bascis @ 3:30.]

[Update 04/20/2016: The 3.0 version of the Test Adapter has just been released. When using NUnit 3.0, be sure to use the "NUnit3TestAdapater" package from NuGet. When using NUnit 2.0, use the "NUnitTestAdapter" package from NuGet. More information here: Integrating NUnit into Visual Studio - Update for NUnit 3]

Version Mismatch
I suspected I might run into a problem when I saw the icons in NuGet:


I needed to add the first and third packages from this list. I noticed that the top one (the NUnit testing framework) had a new icon. And it didn't match the NUnitTestAdapter (the part that plugs into the Visual Studio Test Runner).

During the demo, I just hoped for the best. Unfortunately, this didn't work out so well.

Further Investigation
After the demo, I did some further investigation and found that the version numbers were, in fact, different.

NUnit framework version 3.0.0

NUnit test adapter version 2.0.0

NUnit 3.0 was *just* released. Unfortunately, the test adapter for version 3.0 had not yet been released (CTP 7 was available when I looked into this).

The Working Version
So one question is why did my pre-built version of the project work? Well, the NuGet packages that were saved off with the project were both for the 2.0 release of NUnit. Here's a screenshot from the video that shows the side-by-side build:

Previous NuGet packages showing 2.0 icons
This has the icons that I was expecting to see on Wednesday. Since I didn't refresh my NuGet packages, I kept using the versions previously downloaded, and everything worked as expected.

As a reminder, you can see the videos and get other materials from the presentation on my website: Unit Testing Makes Me Faster.

Starting from Scratch
So the next question is how would we follow along with this sample if we wanted to start from scratch? The answer is that we just need to get the previous version of NUnit from NuGet.

In addition to the "Install" option in NuGet, we also have the option to "Downgrade":

Downgrade to Prior NUnit version

When we do this, we can select the latest 2.0 version (2.6.4) or another version from the drop-down. If we install the 2.6.4 version of NUnit with the 2.0.0 version of the Test Adapter, then everything works as expected.

[Note: The latest NuGet package manager does not have a specific "Downgrade" option. Instead, you just pick the version you want from the "Version" drop-down, then click the "Install" or "Update" button.]

(An alternate solution is to get the pre-release version of the Test Adapter, but I don't normally use pre-release software. I like for other folks to shake out the bugs a bit first.)

This is a short-term problem. Hopefully in the very near future, the 3.0.0 version of the Test Adapter will be released, and we can go back to doing things the easy way.

Wrap Up
Things don't always go as we expect. And that's okay. But we should take the time to review what happened, try to figure out the core issue, and put steps in place to make sure it doesn't happen again.

In my case, I have another demo project that has the skeleton of the testing library. In that project, the NuGet packages for NUnit have already been included in the project. That means they don't need to download live, and we know that the version we have will work for the presentation. I actually already had this project so that I could still run this demo without a live internet connection, but I decided to take the chance at Live! 360 since I had good network access.

I had a great time presenting at Live! 360, and I'll look forward to coming back and doing it again.

Happy Coding!

2 comments:

  1. I see no "Downgrade" option; all I see in NuGet for NUnit is "Install" and then, after installing, "Unintsall" - no "Downgrade" option...

    ReplyDelete
    Replies
    1. The NuGet manager in Visual Studio has been updated a few times. If you have the current version, you should see a "Version" dropdown with an "Update" button next to it. Just pick a different version and hit the update.

      Delete