开发者

SVN hook to check a change was also made to the corresponding Test class

Has anyone come across an SVN pre-commit hook that works with the following logic?

If "MyClass.java" has been modified and is being committed, then there must also be a modification to "MyClassTest.java", by naming convention.

The goal here is to make sure that a developer made changes to the corresponding unit test, when s/he changed a piece of code.

I know this can be cheate开发者_运维问答d by simply changing a little bit of formatting. But the goal is not to stop cheating. It is to very strongly encourage test driven development in a team that is moving to it.

A bonus would be, for when the change is just a refactor, for the hook to ignore the check if the submit comment has the word "REFACTOR". (after all pure refactors should always be committed by themselves)


If what you want to achieve is an "enforcement" of unit testing, I suggest checking in the post-commit (test do run slower than the usual commit operation) if the test coverage decreased for any class. even more, put that check in your Continuous Integration server.

Of course, this may lead to "stupid" test of get and set just to get more coverage. This can be "prevented" by assigning a coverage threshold and alert only if the threshold is reached.

This way you can sell the team the idea of a "mechanism to alert us if we make a mistake" instead of "a mechanism to punish you if you do wrong".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜