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.


3 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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s