以下 TestNG (6.3) 测试用例生成错误“Invalid context for the recording of Expectations”
@Listeners({ Initializer.class })
public final class ClassUnderTestTest {
private ClassUnderTest cut;
@SuppressWarnings("unused")
@BeforeMethod
private void initialise() {
cut = new ClassUnderTest();
}
@Test
public void doSomething() {
new Expectations() {
MockedClass tmc;
{
tmc.doMethod("Hello"); result = "Hello";
}
};
String result = cut.doSomething();
assertEquals(result, "Hello");
}
}
正在测试的课程如下。
public class ClassUnderTest {
MockedClass service = new MockedClass();
MockedInterface ifce = new MockedInterfaceImpl();
public String doSomething() {
return (String) service.doMethod("Hello");
}
public String doSomethingElse() {
return (String) ifce.testMethod("Hello again");
}
}
我假设因为我使用了 @Listeners 注释,所以我不需要 javaagent 命令行参数。这个假设可能是错误的......
谁能指出我错过了什么?