我一直在用史波克写我的测试。但是为了测试等于哈希代码契约,我尝试使用EqualsVerifier。所以我的测试代码看起来是:
def "test equals hashcode contract"() {
EqualsVerifier.forClass(Content.class).verify();
}但这看起来不像它和spock一起运行。
我怎么才能解决这个问题?我希望在我的测试中使用spock。
发布于 2015-06-07 16:03:31
这一切都是正确的,但在spock中它有一点不同,请参见:
@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 {}这个规范失败了,因为异常是引发的- SomeClass需要纠正。看看伟大的文档。
https://stackoverflow.com/questions/30689553
复制相似问题