使用Android Studio进行测试:NoClassDefFoundError:org/testng/TestNG [英] Testning with Android Studio: NoClassDefFoundError: org/testng/TestNG

查看:230
本文介绍了使用Android Studio进行测试:NoClassDefFoundError:org/testng/TestNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试使用内置的testTool为mainActivity生成一些测试,到目前为止,我已经设法生成了一个测试类,并且其中有空方法可以测试mainActivity的方法.如果我在覆盖范围内运行testClass,则会出现此错误:

So I am trying to use the built in testTool to generate some test for my mainActivity, so far I have managed to generate a test class and I got empty methods in it to test the methods of mainActivity. If I run the testClass with coverage I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNG
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 18 more

我不确定这到底意味着什么,有一个未定义的类吗?

I'm not sure what this really means, there is a class that is not defined?

我可能还会添加我添加的内容:

I might also add that I added:

    task testClasses {
    doLast {
        println 'This is a dummy testClasses task'
    }
}

在我的sqlite模块的build.gradle文件中,否则我根本无法运行任何测试.

in the build.gradle file for my sqlite module, otherwise I couldn't run any test at all.

我还可以在模块设置"下的依赖关系"选项卡上添加"org.testng:testnb:6.9.6"设置为测试编译".

I might also add that under Dependencies tab under Module settings, I do have "org.testng:testnb:6.9.6" set to "Test compile".

这是我的依赖项在我的gradle文件中的样子:

This is how my dependencies look in my gradle file:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    androidTestCompile 'org.testng:testng:6.9.6'
    compile project(':sqlite-jdbc-3.8.11.2')
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.getbase:floatingactionbutton:1.10.1'
    compile 'com.android.support:design:23.3.0'
    compile 'com.github.PhilJay:MPAndroidChart:v2.1.6'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.numetriclabz.numandroidcharts:numandroidcharts:1.0.13'
}

我看到Android Studio还创建了一个ExampleUnitTest文件,如果我将测试用例添加到该文件中并运行它们,它就可以正常工作.当我尝试运行整个MainActivityTest类时,似乎只会发生此问题,但是可以测试单个方法.

I saw that Android studio also created an ExampleUnitTest file and If I add my testcases to this file and run them, it works just fine. The problem only seems to happen when I try to run the whole MainActivityTest class, but individual methods seems to be ok to test.

推荐答案

检查您的模块结构.您的高级模块文件夹之一可能没有依赖性. (您可以将模块链接在一起,并且一切正常.)

Check your module structure. Probably one of your high level module folders doesn`t have dependencies. (You can link modules together and everything should work).

转到-> File|Project structure|Modules|*your module*|Dependencies. 这不是TestNG问题,而是模块结构问题.

Go to -> File|Project structure|Modules|*your module*|Dependencies. It's not a TestNG issue, it's a module structure issue.

更多详细说明,请单击此-> 链接

More detailed description Click This -> Link

这篇关于使用Android Studio进行测试:NoClassDefFoundError:org/testng/TestNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆