使用基于 Gradle 的配置时,在 Android Studio (IntelliJ) 上运行简单的 JUnit 测试 [英] Running simple JUnit tests on Android Studio (IntelliJ) when using a Gradle-based configuration
问题描述
我正在使用 Android Studio/IntelliJ
来构建现有的 Android
项目,并想添加一些简单的 JUnit
单元测试.添加此类测试的正确文件夹是什么?
I am using Android Studio/IntelliJ
to build on an existing Android
project and would like to add some simple JUnit
unit tests. What is the right folder to add such tests on?
android Gradle
插件定义了一个目录结构,src/main/java
为主要源代码,src/instrumentTest/java
> 用于 Android
测试.
The android Gradle
plug-in defines a directory structure with src/main/java
for the main source code and src/instrumentTest/java
for Android
tests.
尝试在 instrumentTest 中添加我的 JUnit 测试对我不起作用.我可以将它作为 Android
测试运行(这就是该目录的用途),但这不是我想要的 - 我只想运行一个简单的 JUnit
测试.我尝试为这个类创建一个 JUnit 运行配置,但这也不起作用 - 我猜是因为我正在使用一个标记为 Android
Test 而不是 Source 的目录.
Trying to add my JUnit tests in instrumentTest didn't work for me. I can run it as an Android
test (that's what that directory seems for) but that's not what I'm looking for - I just want to run a simple JUnit
test.
I tried creating a JUnit run configuration for this Class but that also didn't work - I'm supposing because I'm using a directory that is flagged as Android
Test instead of Source.
如果我创建一个新的源文件夹并在项目结构中将其标记为这样,则下次 IntelliJ
从 gradle 构建文件刷新项目配置时,这将被擦除.
If I create a new source folder and marki it as such in Project Structure, this will get wiped next time IntelliJ
refreshes the project configuration from the gradle build files.
在 IntelliJ
上的基于 gradle 的 android 项目中配置 JUnit 测试的更合适的方法是什么?为此使用哪种目录结构?
What is the more appropriate way of configuring JUnit tests in an gradle-based android project on IntelliJ
? Which directory structure to use for this?
推荐答案
从 Android Studio 1.1 开始,答案现在很简单:http://tools.android.com/tech-docs/unit-testing-support
As of Android Studio 1.1, the answer is now simple: http://tools.android.com/tech-docs/unit-testing-support
这篇关于使用基于 Gradle 的配置时,在 Android Studio (IntelliJ) 上运行简单的 JUnit 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!