为什么 Android Studio 会说“未收到测试事件"? [英] Why does Android Studio say "Test events were not received"?

查看:119
本文介绍了为什么 Android Studio 会说“未收到测试事件"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 android 应用程序中进行单元测试,这是我正在做的简单测试教程.

I'm trying to unit test in my android application, and this is the simple test tutorial what i'm doing.

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class ServerListManagerTest extends AndroidTestCase{

   @Test
   public void testTrueIsTrue() throws Exception {
    assertEquals(true, true);
    }
}

目录是这样的,src\main\androidTest\java\some packages\ServerListManagerTest.java

我尝试更改此目录,并构建配置.但是 android studio 虽然构建成功,但仍然无法识别我的单元测试.

I tried changing directory of this, and also build configuration. but android studio still doesn't recognize my unit test though build was successful.

这是我在应用中的 build.gradle,

This is my build.gradle in app,

apply plugin: 'com.android.application'

android {
   compileSdkVersion 21
   buildToolsVersion "21.1.2"

   defaultConfig {
       applicationId "com.kaist.se.pmpapp"
       minSdkVersion 16
       targetSdkVersion 21
       versionCode 1
       versionName "1.0"
   }

buildTypes {
       release {
          minifyEnabled false
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
      }
sourceSets { main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] } } }



dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    androidTestCompile 'org.robolectric:robolectric:2.4'
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile group: 'junit', name: 'junit', version: '4.12'
  }

我的代码有什么问题????

What's wrong in my code????

推荐答案

我假设您使用的是 Android Studio 1.2 版,目前是最新的.

I assume you're using Android Studio version 1.2, the latest at this time.

我认为您的代码没有任何问题.根据Jason Atwood 的帖子,问题似乎与 gradle 缓存以前的结果而不是再次运行有关.如果您查看Gradle 控制台",您会看到所有内容都显示UP-TO-DATE".但是,他建议在脚本参数中添加--rerun-tasks"选项对我来说还不够.

I don't think anything is wrong with your code. According to Jason Atwood's post, the problem seems related to gradle caching the previous results and not running it again. If you look at the "Gradle console", you'll see everything say "UP-TO-DATE". However, his suggestion of adding the "--rerun-tasks" option to the script parameters was not sufficient for me.

除了--rerun-tasks"的之外,我不得不关闭进程内构建并强制它调用外部gradlew工具.为此,请转到...

In addition to "--rerun-tasks", I had to turn off the in-process build and force it to call the external gradlew tool. To do this, go to...

File > Settings > Build, Execution, Deployment > Compiler

然后取消选中使用进程内构建"选项.希望未来的 Android Studio 版本能够解决这个问题,我们可以重新启用该选项.

Then un-check the "Use in-process build" option. Hopefully a future release of Android Studio will fix this and we can re-enable that option.

这篇关于为什么 Android Studio 会说“未收到测试事件"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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