下面的TestNG (6.3)测试用例生成错误"Invalid context for The recording of error“
@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命令行参数。这个假设可能是错误的……
谁能指出我错过了什么?
发布于 2011-11-14 19:21:45
在整个测试过程中,JMockit TestNG Initializer必须运行一次,因此在单个测试类上使用@Listeners将不起作用。
相反,只需升级到使用TestNG 6.2+透明工作的JMockit 0.999.11,而不需要指定侦听器或-javaagent参数(除非在JDK1.5上运行)。
https://stackoverflow.com/questions/7898867
复制相似问题