【发布时间】:2015-09-09 00:32:34
【问题描述】:
我想使用 Android Studio 使用 Robolectric 为 Android 应用程序创建一个简单的测试。
好的,这是我在根目录下的 build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
这是我的 app build.gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
sourceSets {
androidTest.setRoot('src/test')
}
defaultConfig {
applicationId "com.example.robe.helloworld"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'junit:junit:4.12'
}
但是当我尝试调用 @RunWith 注释时,IDE (AndroidStudio) 没有找到该注释。那么我需要配置、启用或安装什么才能获得此功能???
关于 Gradle 的信息
./gradlew -v
Gradle 2.4
Build time: 2015-05-05 08:09:24 UTC
Build number: none
Revision: 5c9c3bc20ca1c281ac7972643f1e2d190f2c943c
Groovy: 2.3.10
Ant: Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM: 1.8.0_60 (Oracle Corporation 25.60-b23)
OS: Mac OS X 10.10.3 x86_64
更新
在我的测试类中,我尝试以这种方式使用 RunWith 注释:
package com.example.robe.helloworld;
@RunWith()
public class WelcomeTest {
}
但是使用 Ctrl + 空格,IDE 不会显示注释。
【问题讨论】:
-
你能显示一些日志吗?
-
你怎么称呼@RunWith?
-
@Radix 我更新了答案。我正在重新安装 IDE,但是如果您首先发现错误或者您有任何想法.. ??
标签: android unit-testing android-gradle-plugin build.gradle robolectric