Technology

Running Machine.Spec tests as part of your Xamarin development

Rob Waggott
Rob Waggott
8 Oct 2015
blog post featured image

Recently I've started to write more and more of my unit tests with <a href="https://github.com/machine/machine.specifications" target="_blank">Machine.Specs</a> , for more information on Machine.Specs see their <a href="https://github.com/machine/machine.specifications" target="blank">Github readme here</a>. I much prefer it over alternatives such as <a href="http://www.nunit.org/" target="_blank">NUnit</a> as it enforces a <a href="http://c2.com/cgi/wiki?ArrangeActAssert" target="_blank">Arrange-Act-Assert</a> pattern within your tests, forces you to split your tests into logical classes, removes attribute clutter and makes your tests human-ly readable (useful for project managers, testers and onboarding fellow developers).

Integrating Machine.Specs into Xamarin development

So if you the above has made you see the light how do you go about introducing M.Spec tests into your Xamarin project? Xamarin Studio's Test runner is heavily linked in with NUnit so we can't use that, instead I use a combination of <a href="https://www.npmjs.com/package/grunt" target="">grunt</a>, <a href="https://github.com/gruntjs/grunt-contrib-watch" target="_blank">grunt-watch</a> and <a href="https://github.com/sindresorhus/grunt-shell" target="_blank">grunt-shell</a> to watch my dlls and re-run all tests if they ever change.

Watch

Watch keeps a watch on all files that have changed. Once a file has changed we can kick off whichever grunt tasks we like.

Shell

Shell allows for you to run command line tasks which don't have a corresponding grunt plugin themselves. So in this case we run the Machine.Specifications.Runner.Console from within the nuget packages directory.

Your grunt file will look something like this:

<script src="https://gist.github.com/robert-waggott/ec14456d5e04b526b9e9.js"></script>

Don't worry, your task will still error when a test breaks, but your tests never break right?

Close chatbot
Open chatbot
Open chatbot