JMockit - 初始化问题 [英] JMockit - initialization problem
问题描述
当我使用以下测试时,我得到一个警告:
When I use the following test I get a WARNING:
警告:JMockit是按需初始化的,这可能导致某些测试失败;
请查看文档以获得初始化的更好方法。
WARNING: JMockit was initialized on demand, which may cause certain tests to fail; please check the documentation for better ways to get it initialized.
这是我的测试实现:
package test;
import static mockit.Mockit.*;
import junit.framework.TestCase;
import mockit.*;
import mockit.integration.junit4.*;
import org.junit.*;
import org.junit.runner.*;
import filip.ClassUnderTest;
import filip.LowerClass;
@RunWith(JMockit.class)
public class MockTest extends TestCase {
@MockClass(realClass = LowerClass.class)
public static class LowerClassMock {
@Mock(invocations = 1)
public String doWork() {
return "Mockowanie dziala :D";
}
}
@Before
public void setUp() { setUpMocks(LowerClassMock.class); }
@After
public void tearDown() { tearDownMocks(); }
@Test
public void testJMockit() {
ClassUnderTest classUnderTest = new ClassUnderTest();
classUnderTest.print();
}
}
任何想法?
推荐答案
据我了解,这个例外是抛出当一个人试图调用JMockit方法时,而JMockit没有正确初始化。
As I understand it, this exception is thrown when one attempts to call a JMockit method, while JMockit has not been properly initialized.
确保遵循 JMockit安装说明,尤其是第3点和第4点。如果JMockit jar在类路径中的之后,它可能会导致问题。
Make sure you follow the JMockit installation instructions, especially points 3 and 4. If the JMockit jar comes after the JUnit jar in the classpath, it might cause problems.
这篇关于JMockit - 初始化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!