How to use EqualsVerifier in Spock test

I am writing my tests using spock. But for checking Equals Hashcode contracts, I am trying to use EqualsVerifier . So my test code looks like this:

def "test equals hashcode contract"() {
    EqualsVerifier.forClass(Content.class).verify();
}

      

But that doesn't sound like launching it with Spock.

How can I get around this? I prefer to use spock for my tests.

+3


source to share


1 answer


Everything works correctly, but in spock it is slightly different, see:

@Grab('org.spockframework:spock-core:0.7-groovy-2.0')
@Grab('cglib:cglib-nodep:3.1')
@Grab('nl.jqno.equalsverifier:equalsverifier:1.7.2')

import spock.lang.*
import nl.jqno.equalsverifier.*

class Test extends Specification {
    def 'sample'() {
        when:
        EqualsVerifier.forClass(SomeClass).verify()

        then:
        noExceptionThrown()
    }
}

class SomeClass {}

      



This option does not work because the fix - SomeClass

should be fixed. Have a look at the great docs .

+4


source







All Articles