我想为我的Java代码编写一个预提交钩子,在这里我可以分别运行我的功能测试和单元测试。在bash脚本中,这是我用来防止在周日提交的代码。

if [ date +%w -eq 6 ]; then
  echo "Enjoy your life. Do not work on Sunday!"
  exit 1
  fi
  exit 0


在将代码提交到github之前,可以进行类似的测试。

最佳答案

很抱歉,由于我不熟悉该语言,所以无法提供bash的答案,我可以分批提供以下内容。

@ECHO OFF

:Main
set MYDATE=%DATE:~0,3%
if %MYDATE% == Sun (
goto Sunday
) else ( goto Test1 )

:Sunday
echo Enjoy your life. Do not work on Sunday!
pause
exit

:Test1
echo Running tests...
::Your test code here
IF %Test1% == PassTest (
goto Test2
) else ( goto Error )

:Test2
echo Running tests...
::Your test code here
if %Test2% == PassTest (
goto Commit
) else ( goto Error )

:Commit
::Script to commit your code

:Error
ECHO "One or more of the tests have failed."
pause
exit


如您所见,我只是使用if语句来检查测试是否成功(当然,您可以通过在::Your test code goes here section中编写代码来设置这些测试)。 This是一个可以帮助您将批处理转换为bash的网站,或者,如果不能,则希望stackoverflow上的其他用户可以为您提供帮助。就像我说的那样,我很抱歉无法为您提供所需语言的代码。希望这可以帮助。

关于java - 如何编写预提交 Hook 以运行Java的功能测试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31128197/

10-11 22:33
查看更多