can jmockit and robolectric coexist?

淺唱寂寞╮ 提交于 2019-12-03 15:25:31

This should be possible. I haven't tested this, but you can create your own test runner.

Take a look at the source for the JMockit and Robolectric test runners:

Of the two the Robolectric one is much more complicated, so we don't want to duplicate that functionality. The JMockit test runner is fairly simple. It should work to extend the RobolectricTestRunner and include the JMockit functionality.

import mockit.internal.startup.*;
class MyTestRunner extends RobolectricTestRunner {

   static { Startup.initializeIfNeeded(); }

   /**
    * Constructs a new instance of the test runner.
    *
    * @throws InitializationError if the test class is malformed
    */
   public MyTestRunner(Class<?> testClass) throws InitializationError
   {
      super(testClass);
   }
}

At version Version 1.8 (Apr 27, 2014) JMockit can work in conjunction with Robolectric.

JMockit now works fine with the Robolectric Android testing tool (tested with Robolectric 2.2 and 2.3).

http://jmockit.org/changes.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!