Nancy and NCrunch - Playing nicely together...at last
If you haven’t tried NCrunch before then stop reading this and go download the trial and try it out, it will forever change your testing habits* - for the better.
NCrunch is the breakfast of champions
-KenR
At DrDoctor we use Nancy (rather than the typically used ASP.Net MVC Framework) the main reason is summed up by the overall goal of the framework:
The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions.
One of the greatest things about Nancy vs ASP.Net MVC is that everything can be tested, and we have tests for pretty much all of our Modules (read Controllers) as well as our Views. NCrunch does some serious magic when it comes to running your test intelligently in parallel. Up until a few days ago I couldn’t figure out how to get my tests to work.
Testing Nancy Views
Testing Nancy Views is very easy, for demonstration purposes I created a new Nancy project from the standard ASP.Net and Razor Nancy template.
The template creates a module called IndexModule which returns a view called Index.
|
|
I then created an MS Test project called specs, and added the following test to make sure that when someone browses to “/” they would be served up the Index view
|
|
To make this work I needed to implement my own custom IRootPathProvider,
|
|
In the Specs project I reference the TestingDemo project and then added the Nancy.Testing and Nancy Razor View Engine (since I’m testing Razor views) NuGet packages.
At this point the test passes in the visual studio test runner, but fails in NCrunch.
Eating Nancy tests with NCrunch
To get the tests to pass in NCrunch you will need to make a few changes to the NCrunch configuration for the test project.
-
Open the NCrunch configuration window from the NCrunch menu and select the test project (below mine is called Specs)
-
Under General select “Additional files to include”
-
Click the button with three dots (see highlighted in red above), on the Additional Files to Include dialog click “Add Directory”
-
Browse to and select the root folder of your Nancy project, then click OK
-
You will see the folder appear in the Additional Files To Include window, click OK
-
Back in the NCrunch configuration window, under Build Settings set “Copy referenced assemblies to workspace” to True
-
You can now close the NCrunch configuration window
-
You should see that the test has now passed in the NCrunch Tests window
*May not actually change your testing habits.
🍪 I use Disqus for comments
Because Disqus requires cookies this site doesn't automatically load comments.
I don't mind about cookies - Show me the comments from now on (and set a cookie to remember my preference)