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

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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?




2 Answers
2



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.


androidTest



Courtesy: The codelab guys



UPDATE:



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


Android Studio 3.1


gradlew connectedDebugAndroidTest





this is kind of ridiculous that this works (thanks for the answer)...you can't right click on a test and run it, but you can right click on the parent folder and run it....I'm new to android but the testing seems so broken....
– jacoballenwood
Feb 23 at 17:39







@jacoballenwood Ya it's broken in kotlin. If you are writing your tests in Java, it works perfectly. But write now, the tooling doesn't fully support Kotlin. Hope they fix it soon.
– Henry
Feb 24 at 7:44





@jacoballenwood Check my updated answer. This is fixed in the latest Android Studio.
– Henry
Mar 12 at 16:46



I was having the same problem. In my case what solved the issue was moving my test class (DaoTest class) to the same package as the default ExampleInstrumentedTest created by Android Studio.



I had this Project structure before:
- src
- androidTest
- java
-[my app package]
- ExampleInstrumentedTest
- itemList.DataSource
- DaoTest



and changed to be:
- src
- androidTest
- java
-[my app package]
- ExampleInstrumentedTest
- DaoTest



After doing this I was able to run all the tests in the class at once without any problems.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

7WytcRXG 7
VyNUx8VJHxh7J2JOkGA Syt6B

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results