Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Coming from a native development background, I'm used to my unit test runners outputting the file and line that caused the test failure. This allowed me to run the tests as a post-build step, and if any test failed the build would fail. Also, I could press the hotkey and jump directly to the offending line.

What I'm discovering in the .Net world is that no one appears to work this way. I'm willing to admit that perhaps there is a different, better way of doing things in this alternate universe, but I would like to know what that is. I don't want to need an external tool (awful), and I don't want to have to remember to compile and then run my tests.

What I really want is what I used to have: failing tests also fail the build, and a quick press of a hotkey would jump me to the test that failed.

Edit: I should add that I'd like to see some sort of integration with Visual Studio's csproj file format. Having a custom MSBuild Task would be great, but I'd be perfectly happy with a console command that I put inside an Exec or AfterBuild.

share|improve this question
4  
What unit test framework are you using? –  epotter Jun 1 '11 at 16:43
    
I've looked at MSTest, NUnit, and xUnit. All of them have command-line test runners or MSBuild integration. None of them output sourcefile(lineno): message, instead I get projectfile(lineno): message. –  moswald Jun 1 '11 at 18:14
    
I use TestDriven.Net and Gallio which both have plugins for VS 2010, and give file->line number resolution –  Matt Ellen Jul 6 '11 at 14:54

4 Answers 4

NAnt is popular with .NET developers to create build scripts. You can use it to create various build targets, such as: compile, unit test, run code coverage, acceptance test, publish etc.

You can set up dependencies between targets, e.g. unit-test depends on compile, acceptance test depends on unit test, etc. If a target fails, dependent targets do not run.

Output from each target goes into a build log file, it is there that you can log your test errors.

With most tasks that your build targets will run (e.g. nunit2 that can be used to run unit tests) you can specify failonerror="true" to make the build fail if you didn't get the expected result (e.g. all tests pass).

share|improve this answer
    
Edited my post a bit, re: using NAnt. I've used it before, but I'd prefer to stick with MSBuild for the IDE integration. –  moswald Jun 1 '11 at 18:17

If it is available to you, you can configure builds wtihin Team Foundation Server. This link may help - Configure Your Build System

share|improve this answer
up vote 0 down vote accepted

Since no one has adequately explained why I would want to change my ways, I have implemented the solution myself. I forked xUnit to fix the output from their MSBuild build Task.

share|improve this answer

I've previously got this to work by running nUnit's Console Runner in a post-build step and then using the XML output format of nUnit and piping that through an XSLT using a small XSL file we wrote to produce the file(line): what format for test failures.

IIRC I raised a bug with the nUnit team to get them to enhance the XML output to make this a bit easier - but this page implies that this works already. Are you using the latest version?

share|improve this answer
    
I was using whatever version was current at the time I asked this question (June 1, 2011). I don't actually know what version that was, since I've switched to xUnit. –  moswald Jul 6 '11 at 18:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.