Visual Studio – Trigger a xUnit test run after project build event

To trigger a xUnit test run after a successful build,
add this to the project “Build Events” / “Post-build event command line:”

"$(SolutionDir)\packages\xunit.runner.console.2.2.0\tools\xunit.console.x86.exe" "$(TargetPath)"

(You need xUnit runner console nuget package installed for this, above is for the 2.2.0 version).
Will produce something similar to this in the Output window “Build”:

 xUnit.net Console Runner (32-bit .NET 4.0.30319.42000)
 Discovering: MyApp.UnitTests 
 Discovered: MyApp.UnitTests 
 Starting: MyApp.UnitTests 
 Finished: MyApp.UnitTests 
=== TEST EXECUTION SUMMARY ===
 MyApp.UnitTests Total: 8, Errors: 0, Failed: 0, Skipped: 0, Time: 1,120s

Docs:
https://xunit.github.io/docs/getting-started-desktop.html#run-tests

Leave a Reply

Your email address will not be published. Required fields are marked *