android - 如何在 android studio 中运行 JUnit 测试?

标签 android android-studio android-testing

我认为instrumentTest中的测试应该与android相关,所以我需要添加一个额外的源文件夹如src/test/java吗? 看起来 src/test/java 中的测试文件没有编译。

如何独立运行 junit 测试?

如何只在命令行中运行 junit 测试,而没有关于 android 的 instrumentTest?

enter image description here

enter image description here

或者 将junit test放在instrumentTest文件夹下调用

     ./gradlew connectedInstrumentTest

但是,单元测试根本不会运行。

最佳答案

如果您的 build.gradle 中只有 Android 插件,我认为这是不可能的。 Android 插件中唯一支持的测试位于 InstrumentTest 文件夹中。普通测试文件夹仅供其他插件使用。

除此之外,可能还需要 Android Studio 本身的支持。但不确定。

关于android - 如何在 android studio 中运行 JUnit 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17229180/

相关文章:

android - fragment后台任务访问资源经常返回illegalStateException

android - 未找到中央目录条目 (ZipException)

android - 确定 mediaplayer 的 opencore 或 stagefright 框架?

java - Android studio - 包 sun.misc 不存在

android - android构建所需的最少文件

android - 如何检查当前 Activity 前面是否有对话框?

Android Studio,模拟器未运行最新版本

android-intent - Android espresso 匹配意图与 bundle 内的 bundle

android - 将 JUnit 测试移植到 Android 测试框架

java - Mockito 测试 RestClient aSync