我正在做一些非常基本的Spock刷新训练,我正在尝试做一个数据驱动的测试。以下是规格说明:
package drills
import drills.StringReverse
import spock.lang.Specification
import org.junit.Test
class TestSpockReverseString extends Specification {
@Test
def "test"(String inString, String expectedString){
given:
StringReverse systemUnderTest = new StringReverse();
when:
String actualString = systemUnderTest.reverseString(inString);
then:
expectedString.equals(actualString)
where:
inString | expectedString
null | null
"" | ""
"abc" | "cba"
"aaa" | "aaa"
"abcd" | "dcba"
"asa" | "asa"
}
}每次我运行它时,我都会得到这样的错误:
我已经阅读了Spock文档并在线阅读了其他示例,看起来我设置的规范是正确的。我正在运行用于EE Java的Eclipse IDE。版本2020-03 (4.15.0)
我需要更新一些设置才能让Groovy和Spock正常工作吗?
任何想法都将不胜感激。
更新:我尝试使用这里的一种规格:
https://github.com/spockframework/spock-example/blob/master/src/test/groovy/DataDrivenSpec.groovy
也就是这个:
def "minimum of #a and #b is #c"() {
expect:
Math.min(a, b) == c
where:
a | b || c
3 | 7 || 3
5 | 4 || 4
9 | 9 || 9
}与上面的问题相同。我认为我的Eclipse设置有问题。我看过groovy编译器,测试运行器,但不知道还能去哪里看。再说一次,任何想法都会受到欢迎。谢谢。
发布于 2020-09-21 08:57:04
您希望在Spock测试中去掉JUnit @Test注释,然后它将使用或不使用feature方法参数。以下是您的规范的一个不太冗长且更"spockish“的版本:
package de.scrum_master.stackoverflow.q63959033
import spock.lang.Specification
import spock.lang.Unroll
class TestSpockReverseString extends Specification {
@Unroll
def "reversing '#inString' yields '#expectedString'"() {
expect:
expectedString == new StringReverse().reverseString(inString)
where:
inString | expectedString
null | null
"" | ""
"abc" | "cba"
"aaa" | "aaa"
"abcd" | "dcba"
"asa" | "asa"
}
static class StringReverse {
String reverseString(String string) {
string?.reverse()
}
}
}顺便说一句,@Unroll在Spock 2.0中将是默认的,你只需要在1.x版本中使用它。
https://stackoverflow.com/questions/63959033
复制相似问题