我想使用Espresso和JMockito.
但我不进行测试.
如果你有解决方法,请帮助我.
我写了一些文件(build.gradle(app,project),Test java)如下.
的build.gradle(APP)
apply plugin: 'com.androID.application'androID { compileSdkVersion 22 buildToolsversion "22.0.1" defaultConfig { applicationID "burning.tutorial" minSdkVersion 21 targetSdkVersion 22 versionCode 1 versionname "1.0" testInstrumentationRunner "androID.support.test.runner.AndroIDJUnitRunner" } packagingOptions { exclude 'liCENSE.txt' exclude 'meta-inf/liCENSE' exclude 'meta-inf/liCENSE.txt' exclude 'meta-inf/NOTICE' } buildTypes { release { MinifyEnabled false proguardfiles getDefaultProguardfile('proguard-androID.txt'), 'proguard-rules.pro' } }}dependencIEs { compile filetree(dir: 'libs', include: ['*.jar']) // App's dependencIEs, including test compile 'com.androID.support:support-annotations:22.2.0' // JMockit androIDTestCompile 'org.jmockit:jmockit:1.18' androIDTestCompile 'com.androID.support.test.espresso:espresso-core:2.2' androIDTestCompile 'com.androID.support.test:runner:0.3'}
的build.gradle(项目)
projects/modules.buildscript { repositorIEs { jcenter() } dependencIEs { classpath 'com.androID.tools.build:gradle:1.3.0' // NOTE: Do not place your application dependencIEs here; they belong // in the indivIDual module build.gradle files }}allprojects { repositorIEs { jcenter() }}
MainActivityTest.java
import androID.support.test.espresso.matcher.VIEwMatchers;import androID.support.test.rule.ActivityTestRule;import androID.support.test.runner.AndroIDJUnit4;import androID.test.suitebuilder.annotation.LargeTest;import org.junit.Rule;import org.junit.Test;import org.junit.runner.RunWith;import static androID.support.test.espresso.Espresso.onVIEw;import static androID.support.test.espresso.assertion.VIEwAssertions.matches;import static androID.support.test.espresso.matcher.VIEwMatchers.withID;@RunWith(AndroIDJUnit4.class)@LargeTestpublic class MainActivityTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class); @Test public voID sampletest() throws Exception { onVIEw(withID(R.ID.age)).check(matches(VIEwMatchers.isdisplayed())); }}
此测试运行时,发生如下错误.
:app:preDexDeBUGAndroIDTest UP-TO-DATE:app:dexDeBUGAndroIDTestUNEXPECTED top-LEVEL EXCEPTION:com.androID.dex.DexException: Multiple dex files define Lorg/junit/runner/Runner; at com.androID.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.androID.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.androID.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.androID.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.androID.dx.merge.DexMerger.merge(DexMerger.java:189) at com.androID.dx.command.dexer.Main.mergelibraryDexBuffers(Main.java:454) at com.androID.dx.command.dexer.Main.runMonoDex(Main.java:303) at com.androID.dx.command.dexer.Main.run(Main.java:246) at com.androID.dx.command.dexer.Main.main(Main.java:215) at com.androID.dx.command.Main.main(Main.java:106)Error:Execution Failed for task ':app:dexDeBUGAndroIDTest'.> com.androID.IDe.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2information:BUILD Failed
解决方法:
简短回答:
你不能轻易解决这个问题,因为JMockit有一个错误的JUnit依赖.要修复它,您需要先修复JMockit.
答案很长:
您的应用包含org.junit.runner.Runner两次:
>通过JMockit,因为它包含库中的Runner类文件(这很糟糕,因为它只包含Runner类而不是整个库).
>通过com.androID.support.test:runner,因为它的一个依赖项是junit库(这是添加JUnit支持的正确方法).
正常修复是排除以下之一:
>排除JMockit的JUnit依赖项:
这不起作用,因为JUnit未定义为正确的依赖项. JUnit只是粘贴在自己项目中的类文件中.这是一件坏事.
>为com.androID.support.test排除JUnit依赖项:runner:
我们可以做到这一点,但是这将删除JMockit没有放入项目的junit库中的所有其他类.这将有效地破坏您使用的任何其他junit代码.
如果您真的需要使用JMockit,那么您可以考虑编辑项目,使其正确包含junit依赖项,然后重新编译它并以这种方式将其添加到项目中.
这显示了错误的依赖:
您可以看到Runner类是如何粘贴到项目中的.
修复JMockit依赖项后,需要按如下方式添加JMockit:
androIDTestCompile ('org.jmockit:jmockit:1.18') { exclude group: 'junit'}
总结 以上是内存溢出为你收集整理的如何使用Espresso JMockit全部内容,希望文章能够帮你解决如何使用Espresso JMockit所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)