Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测试运行不正常-Android_Android_Unit Testing_Junit - Fatal编程技术网

测试运行不正常-Android

测试运行不正常-Android,android,unit-testing,junit,Android,Unit Testing,Junit,在我的项目上运行测试时,我面临一个问题。我正在使用JUnit、Mockito和PowerMock 我有一个测试类,我可以从Android Studio运行,并且运行良好(6/6)。但是,如果我使用命令/gradlew test而不是从中执行此操作,则其中三个会因错误而失败: MyTestsClass.java:166处的java.lang.NoClassDefFoundError 搜索该行时,我可以看到它正在调用一个方法(因此我认为错误并不在那里,而是在调用的某个地方) 它怎么可能从命令失败并从

在我的项目上运行测试时,我面临一个问题。我正在使用JUnit、Mockito和PowerMock

我有一个测试类,我可以从Android Studio运行,并且运行良好(6/6)。但是,如果我使用命令
/gradlew test
而不是从中执行此操作,则其中三个会因错误而失败:

MyTestsClass.java:166处的java.lang.NoClassDefFoundError

搜索该行时,我可以看到它正在调用一个方法(因此我认为错误并不在那里,而是在调用的某个地方)


它怎么可能从命令失败并从AS工作?这两者有什么区别?是什么导致了这个错误?

可能是因为您的依赖关系

您没有在测试中定义它们,它不会编译。例如:

// Needed to compile    
compileOnly 'com.madgag.spongycastle:prov:1.54.0.0'

// Needed to compile tests
testImplementation 'com.madgag.spongycastle:prov:1.54.0.0'

可能吗?

我也遇到了同样的问题,但我还没有找到解决方案。是的,确实有效。我没有意识到我需要那个改变,谢谢!