Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Android Studio say "Test events were not received"?

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);
    }
}

The directory is like this, src\main\androidTest\java\some packages\ServerListManagerTest.java

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

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????

like image 805
W.Cointreau Avatar asked May 22 '15 10:05

W.Cointreau


People also ask

What is test folder in Android Studio?

By default, Unit tests are written in src/test/java/ folder and Instrumentation tests are written in src/androidTest/java/ folder. Android studio provides Run context menu for the test classes to run the test written in the selected test classes.

What is filter includeTestsMatching?

includeTestsMatching. TestFilter includeTestsMatching​(String testNamePattern) Appends a test name pattern to the inclusion filter. Wildcard '*' is supported, either test method name or class name is supported. Examples of test names: "com.

What is test cases in Android?

You can use the JUnit TestCase class to do unit testing on a class that doesn't call Android APIs. TestCase is also the base class for AndroidTestCase, which you can use to test Android-dependent objects. Besides providing the JUnit framework, AndroidTestCase offers Android-specific setup, teardown, and helper methods.


2 Answers

Sometimes you might have simple a compiler issue and end up with this message. This happened to me.. The compiler issue was not pointed out directly had to scroll down on the stack trace to find what is the issue.

enter image description here

like image 191
Shangeeth Sivan Avatar answered Jan 04 '23 02:01

Shangeeth Sivan


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

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.

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

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.

like image 22
Brian White Avatar answered Jan 04 '23 03:01

Brian White