CodeBork | Tales from the Codeface

The coding blog of Alastair Smith, a software developer based in Cambridge, UK. Interested in DevOps, Azure, Kubernetes, .NET Core, and VueJS.


Project maintained by Hosted on GitHub Pages — Theme by mattgraham

So my promised updates on other things haven’t quite come to fruition… This week’s been kinda busy.

But this evening I sat down with NAnt and NUnit to try and get my Unit Tests working under NUnit and running from the automated NAnt build, and, six hours later, I’m still here.

[img_assist|nid=21|title=|desc=|link=none|align=center|width=427|height=640] The first headache was trying to get the task in NAnt to work with my tests. NAnt ships with NUnit 2.2.8, whereas I've been using the much more up-to-date 2.4.7 version. Very early, I ran into the dreaded "could not load file or assembly" error, and looking again at the docs for the <nunit2> NAnt task I discovered I needed to redirect the assembly bindings via a test.config file, but it took me a very long time to work out that I'd got my oldVersion and newVersion the wrong way round :-(

Line 7 should actually read:

so that my 2.4.7-bound tests can be run with the 2.2.8 binaries provided with NAnt. Something in Scott Hanselman’s post on the subject helped me grasp this fact in a flash of inspiration.

However, Scott recommends invoking nunit-console.exe with the <exec> task — a more generic call-an-external-program sort of task. For example,

Unfortunately, I’m back to square one with this method. Running nunit-console.exe directly from the command line gives me the exact same “could not load file or assembly” error that I was suffering earlier, and, unsurprisingly, I get the same results through my NAnt build:

NUnit version 2.4.7 Copyright (C) 2002-2007 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 5.1.2600 Service Pack 2 CLR Version: 2.0.50727.1433 ( Net 2.0.50727.1433 ) Could not load file or assembly 'nunit.framework, Version=2.4.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified.

Note there that NUnit version 2.4.7 is unable to load the nunit.framework assembly at version 2.4.7. I’ve trashed my test.config file, so I’m not doing any assembly re-binding any more, and NUnit is housed within it’s own directory in my working copy. Goodness only knows what’s going on here — maybe I’ll find out tomorrow…