Run testng test in Git pre-commit hook

左心房为你撑大大i 提交于 2019-12-23 02:21:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!