我需要启用或安装什么才能获得注释 @RunWith
What do I need enable or install to get the annotation @RunWith
我想使用 Android Studio 为 Android 应用程序创建一个 Robolectric 的简单测试。
好的,这是我的 build.gradle 在根目录:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
这是我的应用 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
更新
在我的测试中 class 我试图以这种方式使用 RunWith 注释:
package com.example.robe.helloworld;
@RunWith()
public class WelcomeTest {
}
但是使用 Ctrl + space IDE 没有显示注释。
它在 Android 测试支持库中。将以下内容添加到您的依赖项中:
androidTestCompile 'com.android.support.test:runner:0.3'
已经存在:
testCompile 'junit:junit:4.12'
在 Android studio 中唯一要做的一件事就是从仪器测试切换到单元测试:
我想使用 Android Studio 为 Android 应用程序创建一个 Robolectric 的简单测试。
好的,这是我的 build.gradle 在根目录:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
这是我的应用 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
更新
在我的测试中 class 我试图以这种方式使用 RunWith 注释:
package com.example.robe.helloworld;
@RunWith()
public class WelcomeTest {
}
但是使用 Ctrl + space IDE 没有显示注释。
它在 Android 测试支持库中。将以下内容添加到您的依赖项中:
androidTestCompile 'com.android.support.test:runner:0.3'
已经存在:
testCompile 'junit:junit:4.12'
在 Android studio 中唯一要做的一件事就是从仪器测试切换到单元测试: