Using NUnit and C# with Mono and MonoDevelop on OS X

This is a quick post highlighting how to use NUnit for unit testing your C# code on a Mac. Of course, we know C# code can be run on a Mac OS X environment, using Mono and MonoDevelop, and so my intuition was that I should be able to somehow use NUnit on it as well, perhaps with something as simple as

$ mono nunit-console.exe dll_file.dll

or something like that. I downloaded the latest version of the NUnit binaries and tried compiling and running my test code with

$ mcs file_a.cs file_a_test.cs -reference:/path/to/nunit.framework.dll

$ mono /path/to/nunit-console.exe file_a.exe

Of course it didn’t work. I don’t know why and I don’t know how I found it, but after tinkering around with it for a bit I discovered that when I had installed Mono on my Mac a long time ago, it had already installed NUnit on it. NUnit was pre-packaged with Mono and MonoDevelop! All I had to do then to successfully run what I wanted to run was:

$ mcs file_a.cs file_a_test.cs -reference:nunit.framework.dll

$ NUNIT-CONSOLE file_a.exe

Notice how I didn’t need the path anymore, and how NUNIT-CONSOLE is a symbolic link to nunit-console.exe that came with Mono.

Got rid of the freshly unzipped (and now superfluous) NUnit.

5 thoughts on “Using NUnit and C# with Mono and MonoDevelop on OS X

  1. Thanks for sharing!
    Same thing for fsharp:
    $ fsharpc file_a.fs -r /path/to/nunit.framework.dll
    $ mono /path/to/nunit-console.exe file_a.exe

  2. My NUNIT-CONSOLE says:

    Note: nunit-console shipped with Mono is deprecated, please use the NUnit NuGet package or some other form of acquiring NUnit.
    NUnit version 2.4.8

    I haven’t figured out how to us any other nunit than the one built into mono (the deprecated one).

Leave a comment