Android Studio 3 beta 2 ClassNotFound in kotlin unit tests

Viewed 227

I am using Android Studio 3.0 beta 2, converted an existing project to gradle plugin 3.0.0-beta2

When I try to run an existing unit test written in kotlin I get 'java.lang.NoClassDefFoundError: com/other/domain/CollectionItem'

The test itself is very simple:

import org.junit.Test

import org.junit.Assert.*

class CollectionViewModelTest {
    @Test
    fun getItemsWithManyItemsWillReturnCollectionItemViewModels() {
        val collectionItems = listOf(CollectionItem(42, "Item1", CollectionItemType.COLLECTION, ""), CollectionItem(43, "Item2", CollectionItemType.COLLECTION, ""), CollectionItem(44, "Item3", CollectionItemType.COLLECTION, ""))
        val collection = Collection(45, "Home", "Home collection", collectionItems, 42)
        val collectionViewModel = CollectionViewModel(collection)

        assertTrue(collectionViewModel.items.first().isFirst)
        assertFalse(collectionViewModel.items.first().isLast)

        assertFalse(collectionViewModel.items[1].isFirst)
        assertFalse(collectionViewModel.items[1].isLast)

        assertTrue(collectionViewModel.items.last().isLast)
        assertFalse(collectionViewModel.items.last().isFirst)
    }
}

It works when I run it from the terminal using ./gradlew

Any ideas why this can happen?

Edit:

This seems to happen only when the test requires classes from other library projects.

In this case CollectionItem is part of another library in the same project and it's included in the gradle file via implementation project(':domain')

Edit

It might also be worth mentioning that domain module is pure java

Edit

Figured out the problem is when the library (domain) has classes written in kotlin, those classes will throw NoClassDefFoundError in unit test's only.

0 Answers
Related