运行这个测试:
@Test
public void testSystemCurrentTimeMillis() {
new NonStrictExpectations(System.class) {{
System.currentTimeMillis(); result = 1438357206679L;
}};
long currentTime = System.currentTimeMillis();
assertEquals(1438357206679L, currentTime);
}
我遇到了一个IllegalStateException错误:
java.lang.IllegalStateException: 在此时缺少对模拟类型的调用;请确保此类调用仅在适当的模拟字段或参数声明之后出现 at unittests.DateTest$1.(DateTest.java:24) at unittests.DateTest.testSystemCurrentTimeMillis(DateTest.java:23)
我的测试有什么问题(使用JMockit 1.18)?