3
Испытано класс:Спока метод рамки коррекции в тестовом классе
public class ClassForTest {
public String hello(){
return "hello " + getClassName();
}
public String getClassName(){
return ClassForTest.class.getName();
}
}
Спок Класс: тест тест
class ClassForSpockTest extends Specification{
def setupSpec(){
ClassForTest.metaClass.getClassName={"ClassForSpockTest"}
}
def "override test"(){
setup:
ClassForTest cft = new ClassForTest()
expect:
cft.getClassName() == "ClassForSpockTest"
}
def "mock test"(){
setup:
ClassForTest cft = new ClassForTest()
expect:
cft.hello() == "hello ClassForSpockTest"
}
}
переопределение пройдена! Mock test crashing, cft.hello() return "hello ClassForTest"
благодарит за ответ –