Question
I'd like to use in my CI pipeline some tool to verify code standards for Spock tests in Groovy. I have looked at archunit, codenarc and sonarcube but didn't find rules for Spock tests written in Groovy. Do you know any such a tool?
Example
There is example of code standard that must be verified by the tool. The test below always passes, however condition true == false is evaluated to false. This happend due to bad usage of helperMethod() is Spock. You could read more about helper methods in documentation.
def "test that always passes"(){
when:
1 + 1
then:
helperMethod()
}
def helperMethod(){
true == false // evaluated to false
true == true
}
I need to verify that developer didn't forget to add assertions in the helper method by using assert, && or verifyAll. Below are valid examples of helper method
def helperMethod1() {
assert true == false
assert true == true
}
def helperMethod2() {
true == false
&& true == true
}
def helperMethod3() {
verifyAll {
true == false
true == true
}
}