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

I am trying unit test in my android app and it is a simple test tutorial what i am 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 as follows: src\main\androidTest\java\some packages\ServerListManagerTest.java

I tried changing the directory of this as well as creating a configuration. but android studio still does not recognize my unit test, although the assembly was successful.

This is my build.gradle in the application,

 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 is wrong in my code ????

+8
android-studio android-gradle unit-testing junit gradle
source share
1 answer

I assume that you are using Android Studio version 1.2, the latest at the moment.

I do not think that something is wrong with your code. According to Jason Atwood , the problem is with gradle caching of previous results and restarting. If you look at the Gradle console, you will see that everyone says "UP-TO-DATE". However, his suggestion to add the "-rerun-tasks" option to the script options was not enough for me.

In addition to --rerrer-tasks, I had to disable the built-in assembly and force it to call the external gradlew tool. To do this, go to ...

 File > Settings > Build, Execution, Deployment > Compiler 

Then uncheck the "Use embedded assembly." I hope that in the future release of Android Studio will fix this, and we will be able to enable this option again.

+19
source share

All Articles