JMockit javaagent未初始化JMockit [英] JMockit javaagent isn't initializing JMockit
问题描述
我已经使用Robolectric设置了JMockit以便与某些JUnit测试一起使用,但是我遇到了错误.我主要是使用Maven来运行测试.
I've set up JMockit for use with some JUnit tests also using Robolectric, but I am getting errors. I'm primarily using maven to run the tests.
当我使用 mvn测试运行测试并且将Javaagent配置为指定的这里,我得到了通常的异常:
When I run the test with mvn test and the javaagent configured as specified here I get the usual exception:
java.lang.IllegalStateException:JMockit没有正确初始化;检查jmockit.jar在类路径中是否在junit.jar之前(如果使用JUnit;否则,请查看文档)
java.lang.IllegalStateException: JMockit wasn't properly initialized; check that jmockit.jar precedes junit.jar in the classpath (if using JUnit; if not, check the documentation)
I have validated that JMockit is on the classpath before JUnit using mvn dependency:build-classpath
and mvn test --debug
. I have also validated that the -javaagent
argument is appropriately being called using mvn test --debug
.
库版本:
- JDK 1.6
- JMockit 1.5
- JUnit 4.8.2
- Robolectric 2.2 Robolectric转轮阻止我使用JMockit转轮.
- Maven 3.0.3
- Surefire 2.14.1
- JDK 1.6
- JMockit 1.5
- JUnit 4.8.2
- Robolectric 2.2 The Robolectric runner prevents me from using the JMockit runner.
- Maven 3.0.3
- Surefire 2.14.1
测试类如下:
@RunWith(RobolectricTestRunner.class)
public class HelpFragTest {
FragmentActivity activity;
FragmentManager fragmentManager;
@Mocked ActionBarManager actionBarManager;
@Before
public void setup() throws Exception {
activity = Robolectric.buildActivity(FragmentActivity.class).create().resume().get();
fragmentManager = activity.getSupportFragmentManager();
MyApplication.instance().setActionBarManager(actionBarManager);
}
@Test
public void testShow(){
new NonStrictExpectations() {{
Helper.staticMethod(anyString, anyString);
actionBarManager.clear();
actionBarManager.setTitle(anyString);
actionBarManager.refresh();
}};
HelpFrag frag = HelpFrag.newInstance();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(frag, StringUtils.EMPTY);
transaction.commit();
assertTrue(frag.isVisible());
}
}
我还尝试了没有显式运行器或JavaAgent的情况,在这种情况下,我从同一代码中得到以下异常:
I've also tried without either the explicit runner or the JavaAgent, in which case I get the following exception from the same code:
java.lang.IllegalStateException:无效的记录期望的地方
java.lang.IllegalStateException: Invalid place to record expectations
推荐答案
我遇到了同样的问题,问题似乎是Robolectric测试运行程序干扰了JMockit-JUnit集成.参见此.
I have run into the same issue, and the problem seems to be that the Robolectric test runner interferes with the JMockit-JUnit integration. See this.
这篇关于JMockit javaagent未初始化JMockit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!