I'm using the following git pre-commit hook to run unit-test on a project prior to commit
echo "Starting test runner..."
exec dotnet test "MyProject.UnitTest.csproj"
if [ $? -ne 0 ]; then
echo >&2 "Tests must pass before commit!"
exit 1
fi
The hook is taken into account in Visual Studio when I commit, but I get a common error: "One or more errors occurred". The hook seems to be working correctly as I do not have any issue if all my unit-test pass.
Do you know a way of showing the output of the hook in visual studio, to get a proper error details ?
For that, I'm afraid you'll have to use the command prompt when committing your changes. You could use the "Package Manager Console" to run your git commands if you do not want to leave Visual Studio. Then you can see the output in the "Source-Control - Git" output window.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With