我需要做什么启用或安装以获得注释@RunWith [英] What do I need enable or install to get the annotation @RunWith

查看:181
本文介绍了我需要做什么启用或安装以获得注释@RunWith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的测试与Robolectric为Android应用采用Android工作室。

I want to create a simple test with Robolectric for Android Apps using Android Studio.

好吧,这是我的根目录下的build.gradle:

Ok, it is my build.gradle on root directory:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

和这是我的应用程序的build.gradle文件:

And it is my app build.gradle file:

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)未找到注解。那么什么才是我需要配置,启动或安装以获得此功能?

But when I try to invoke the @RunWith annotation, The IDE (AndroidStudio) doesn't find the annotation. So what do I need to configure, enable or install to get this feature ???

./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注释是这样的:

UPDATE

In my test class I am trying to use the RunWith annotation in this way:

package com.example.robe.helloworld;

@RunWith()

public class WelcomeTest  {
}

但用Ctrl +空格IDE不显示我的注释。

But with Ctrl + space the IDE doesn't show me the annotation.

推荐答案

这是已经存在:

testCompile 'junit:junit:4.12'

的只有一件事在Android的工作室做的是从仪器测试切换到单元测试:

这篇关于我需要做什么启用或安装以获得注释@RunWith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆