android-perftracking icon indicating copy to clipboard operation
android-perftracking copied to clipboard

[Android][Test] Setup Kotlin for tests

Open NemoOudeis opened this issue 7 years ago • 3 comments

So it looks like we can't use spek because it doesn't work with robolectric see issue #65. Same goes for KotlinTest, see issue #189.

With these limitations I think we can improve the tesk code base with the following setup: Kotlin + junit4 + robolectric + kluent

NemoOudeis avatar Apr 12 '18 06:04 NemoOudeis

Hey! I know this issue is a little bit old, but we just added Robolectric experimental support to KotlinTest.

Perhaps this is what you need for now https://github.com/kotlintest/kotlintest/pull/1014

LeoColman avatar Sep 28 '19 20:09 LeoColman

@Kerooker I have been trying to use the Robolectric support but I get some issues. Please, can you provide the steps to configure it, including the dependencies? Thanks.

eugenio1590 avatar Nov 06 '19 16:11 eugenio1590

Sure! I know this will be a little bit complicated right now, as we are experimenting a lot, but it should work:

First add the snapshot repository to your repositories:

repositories {
    maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
}

Then add the Robolectric Extension dependency to your dependencies:

dependencies {
    testImplementation("io.kotlintest:kotlintest-extensions-robolectric:4.0.2653-SNAPSHOT")
}

Then in your tests that are going to use Robolectric, annotate them with @RobolectricTest.

To get robolectric working, you finally need to add it to your project config (if you don't know how to do that, take a look here)

override fun extensions() = listOf(RobolectricExtension())

LeoColman avatar Nov 08 '19 17:11 LeoColman