如何为 java 的 运行 功能测试编写预提交挂钩

How to write a pre-commit hook to run functional tests for java

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

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 的网站,或者如果您不能,希望 Whosebug 上的其他用户可以帮助您。就像我说的那样,我很抱歉无法以您想要的语言为您提供代码。希望这有帮助。