Lowering The Barrier To Entry For Testing On Linux / Mono With Vagrant

Introduction

We are big fans of Mono on the Nancy project – we have Continuous Integration builds that run on both Mono 2.x, and Mono 3.x (in addition to Microsoft’s .net), and we have TravisCI also performing Mono builds of all pull requests as they come in.

As good as Mono is though, there are still times where we have issues with compatibility. Sometimes these are down to Mono itself, other times it’s a casing issue when running on Linux (which generally has a case sensitive file system, so /Images isn’t the same as /images). Plenty of our contributors are au fait with Mono and Linux, so fixing issues on pull requests isn’t an issue, but for those that aren’t, getting Mono and Linux set, even in a virtual environment can be daunting – and that’s before you even attempt to edit any files!

Introducing Nancy.Vagrant

I’ve discussed Vagrant in a previous post – it’s an excellent tool for automatically spinning up and configuring virtual machines, and we’ve used it to create two scripts that make creating a Linux/Mono test environment for Nancy as simple as typing:

vagrant up
vagrant ssh

And because Vagrant is capable of sharing folders between the host machine and the virtual machine, you can continue to edit the files in Visual Studio (or whatever editor of choice you use locally), and run the build in the Linux / Mono environment. Once you’re all done you can either stop the virtual machine, or delete it completely, using another single command.

Trying It Out

The scripts themselves, as well as instructions on getting up and running and some simple Linux help, can be found over on the Github repository:

https://github.com/NancyFx/Nancy.Vagrant

We hope this helps people get up and running easily with Linux and Mono, whether they’re contributing to Nancy or not.

Debugging xUnit Tests Using MonoDevelop

Introduction

After several months of neglect, we are currently working on getting the Nancy project ship shape on Mono. We’ve gotten to the point now where everything builds and runs just fine, but we have a few tests that fail when running on Linux/Mono. The failures we are seeing are obviously bugs in the tests/stubs/mocks themselves, and we need to debug them to see exactly what’s going on. MonoDevelop has some decent test runner features, but they appear to be heavily tied to NUnit which is a problem if you happen to use xUnit 🙂

Debugging With xUnit

Luckily the solution is relatively simple, if a little clunky:

  1. Download the latest xUnit release and unzip it somewhere.
  2. Set whatever breakpoint you need in MonoDevelop and build the test project (in debug mode, obviously).
  3. In MonoDevelop, go to Run, Debug Application, browse to where you extracted the ZIP from step 1 and choose the appropriate xunit.gui.*.exe depending on your target framework/architecture (xunit.gui.clr4.exe in our case).
  4. The gui xUnit runner will popup – click Assembly, Open, browse to the output of your test project, select the assembly and press OK.
  5. Click Run All in the bottom left.

The runner will run the tests and you should break out into MonoDevelop whenever you hit a breakpoint.

Pretty simple, if a bit of a ballache – but hey, you shouldn’t need to debug your tests very often anyway 🙂