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.
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).
-
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– moswald2011年06月01日 18:17:48 +00:00Commented Jun 1, 2011 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
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.
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?
-
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– moswald2011年07月06日 18:50:49 +00:00Commented Jul 6, 2011 at 18:50
sourcefile(lineno): message
, instead I getprojectfile(lineno): message
.