问题
How would I write a bash script that will run as a git pre-commit hook to fail if a specific testng test fails? I currently run my testng tests through maven surefire like this:
mvn clean test -Dtest="MyTestName"
回答1:
If the pre-commit
hook returns non-zero, then the commit is aborted before it even starts. In a script for a bourne style shell (e.g. sh, ksh, zsh, bash, etc.), by default the return value of the last command run is the return value of the script. As I understand it mvn clean test
should return non-zero on failure, so your script should be as simple as:
#!/bin/sh
mvn clean test -Dtest="MyTestName"
Then just name it pre-commit
in your .git/hooks/
directory in your repo and run chmod ug+x
on it to make sure it can be executed.
来源:https://stackoverflow.com/questions/34100369/run-testng-test-in-git-pre-commit-hook