Thoughts on life, liberty, and information technology

Building with NAnt (and NUnit, and NCover, and NCoverExplorer)

A while back, I wrote a blog post, A quick introduction to Nant, which gave, well, a quick introduction to building C# libraries using NAnt.

Since then, I’ve been using NAnt to do a lot more — notably, to run unit tests and to report on test coverage (using NCover and NCoverExplorer). The usage is pretty straightforward, and I think you’ll see how each step builds on the previous step.

  • To run a default build (excluding unit tests): nant
  • To build all projects and unit tests (but don’t run : nant build-tests
  • To build all projects and unit tests, and run tests using NUnit: nant test
  • To build all projects and unit tests, and run tests using NCover to generate coverage reports: nant cover
  • To build all projects and unit tests, run tests using NCover to generate coverage reports, and open those reports in NCoverExplorer: nant coverex

The sample below is my NAnt build file. A few notes first.

  • There are only two projects referenced: Project1 and Project1.Tests. Repeat the appropriate sections to build against additional projects.
  • nunit-console.exe is expected to be in the system path.
  • nunit-console.exe, ncover.console.exe, and ncoverexplorer.exe are expected to be in the system path. I recommend you download and install TestDriven.Net to have all of these in a convenient place.

Now, on to the build file. It should be self-explanatory, but I added some XML comments for your convenience.



	Project -- NAnt Build
	
	

	
	

	
		
	

	
		
		
			
			
			
		
		
			<!-- I keep shared DLLs in a directory called References -->
			
				
				
			
		
	

	
		
			
				
			
			
				
				<!-- add additional references here -->
			
		
	

	
		
		
			
		
		
		
		
		<!-- add additional references here -->
		
		
		<!-- this copies your App.config to a file that can be found by NUnit when testing -->
		
	

	
		
			
			
		
	

	
		
	

	
		
			
		
	



3 responses to “Building with NAnt (and NUnit, and NCover, and NCoverExplorer)”

  1. josh Avatar
    josh

    This is one of the things I want to get going, but haven’t made the time to do it. IMO a good build process includes automated tests, and this is a good way to do it. nice post.

    Like

  2. Daniel Avatar
    Daniel

    Great Article, Thanks a lot!

    Like

  3. Artel DeVries Avatar
    Artel DeVries

    I replaced the task that builds the project with this:

    This automatically takes care of the references for you.

    Like

Leave a reply to Artel DeVries Cancel reply