Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class not found, Empty test suite in androidTest using Android Studio 3.0.1, Room, Kotlin

I have a problem with running my androidTest.

Here is my setup in gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.blabla.shoppinglistapp"
    minSdkVersion 17
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
 }
}

ext.daggerVersion = '2.11'
ext.roomVersion = '1.0.0'
ext.mockitoVersion = '2.11.0'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-android:2.8.47'

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"

// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'

// Room
implementation "android.arch.persistence.room:runtime:$roomVersion"
implementation "android.arch.persistence.room:rxjava2:$roomVersion"
kapt "android.arch.persistence.room:compiler:$roomVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.10"
androidTestImplementation "android.arch.persistence.room:testing:$roomVersion"

// Gson
implementation 'com.google.code.gson:gson:2.8.2'
}

And here is the test(almost nothing here):

@RunWith(AndroidJUnit4::class)
class ShoppingListDaoTest {
@Test
fun useAppContext() {
    // Context of the app under test.
    val appContext = InstrumentationRegistry.getTargetContext()
    assertEquals("com.blabla.shoppinglistapp", appContext.packageName)
}

private lateinit var database: ShoppingListDatabase

@Before
fun initDb() {
    // using an in-memory database because the information stored here disappears after test
    database = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(),
            ShoppingListDatabase::class.java)
            // allowing main thread queries, just for testing
            .allowMainThreadQueries()
            .build()
}

@After
fun closeDb() {
    database.close()
}


@Test fun testGetActiveShoppingListWhenNoActiveShoppingListInserted() {
    database.shoppingListDao().getActiveShoppingLists()
            .test()
            .assertNoValues()
}


}

When i try to run the test i get this:

Process finished with exit code 1 Class not found: "com.blabla.shoppinglistapp.ShoppingListDaoTest"Empty test suite.

And it is not starting

UPDATE

I noticed some really bad thing. When i started new project in Android Studio and try to run default androidTest it gives me known error:

Error:Gradle: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

The workround for this is to add this line to gradle.properties:

android.enableAapt2=false

This is the steps that I've done in my original project previously(i ran into that error also). Unfortunately, after it it give me the error from my question. So it really is the matter of how to solve the isse with the aapt2 to make this work. See here also: AAPT2 error: check logs for details, after workround the androidTest not working

Any idea?

like image 789
K.Os Avatar asked Dec 25 '17 15:12

K.Os


1 Answers

I too had the same problem. Whenever I tried to run the individual test or test class, I kept getting "Empty Test Suite" error. It seems this is a bug in Android Studio.

Instead, right click the androidTest package and click "Run 'Tests in ...". This is the only way I could get it to work.

Courtesy: The codelab guys

UPDATE:

This is fixed in Android Studio 3.1 version. Even the gradlew connectedDebugAndroidTest issue is now fixed.

like image 151
Henry Avatar answered Oct 18 '22 10:10

Henry