Reputation: 748
In Visual Studio (2017) I have two projects: one containing business logic (MyProject) and one containing some NUnit tests (MyProject.Tests). MyProject has the following Post-Build event:
[path to nunit]\nunit-console.exe [path to MyProject.Tests]\MyProject.Tests.dll
When MyProject is built, the tests in MyProject.Tests are run. The Output window displays detailed results from running the tests in the project, which is great. However, these results are easily lost in the stream of other information to the Output window, especially if other projects are also being built at the same time.
If any tests fail, the following message appears in Visual Studio's Error List:
The command "[path to nunit]\nunit-console.exe [path to MyProject.Tests]\MyProject.Tests.dll" exited with code 3.
This is nice and visible; I like that it's right where I would also find compilation errors, etc. I thought that the Error List would also display each failed unit test as well so I can quickly navigate to each one, but currently it does not.
I've looked through the various command-line options for running NUnit tests from the console, but I haven't found any way yet to format the output in a way that would be recognized by the Error List. Is it possible to do this?
Note: If there is an error during one of the tests (i.e. the test is unable to run due to an error), that error will appear in the Visual Studio Error List. This is not the case for ordinary test failures though.
Upvotes: 0
Views: 838
Reputation: 748
I've got a solution that seems feasible, even though it did take some extra steps. If anyone knows of an easier/more direct solution, feel free to chime in.
I was able to take advantage of two things:
So I created a Simple console project that reads the XML file generated by NUnit, and then prints each test failure to the Console in the needed format. My post-build event now looks like
[path to nunit]\nunit-console.exe [path to MyProject.Tests]\MyProject.Tests.dll /work:[path to results.xml]
[path to my xml parser] [path to results.xml]
Upvotes: 1