在Git预提交钩子中运行testng测试 [英] Run testng test in Git pre-commit hook
问题描述
如果特定的testng测试失败,我将如何编写一个bash脚本作为git pre-commit hook运行以失败?
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"
推荐答案
如果 pre-commit
钩子返回非零值,那么提交会在它开始前中止。在bash脚本中,默认情况下,最后一个命令的返回值是脚本的返回值。根据我的理解, mvn clean test
在失败时应该返回非零值,所以您的脚本应该如此简单:
If the pre-commit
hook returns non-zero, then the commit is aborted before it even starts. In a bash script, by default the return value of the last command run is the return value of the script. By my understanding mvn clean test
should return non-zero on failure, so your script should be as simple as:
#!/bin/sh
mvn clean test -Dtest="MyTestName"
然后在 .git / hooks /
目录中将它命名为 pre-commit
你的repo并运行 chmod ug + x
以确保它可以被执行。
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.
这篇关于在Git预提交钩子中运行testng测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!