Using Kotlin for Android Testing

Many developers are quite optimistic about Kotlin future for Android. It sounds so sweet: less verbose, more type-safety, zero-overhead null-safety, Java interop. But not everyone is ready to take a risk and start writing production code using new programming language. Indeed, it could be not mature enough and will add dependencies which increase method count of APK for more than 6.5K.

But what if we’ll use Android testing using Kotlin?

Project setup

So we can setup Kotlin plugin and related libraries to be only in testCompile dependencies scope. Here is what we should set in build.gradle:

dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
compile ‘com.android.support:appcompat-v7:23.2.0’

testCompile ‘junit:junit:4.12’
testCompile “org.jetbrains.kotlin:kotlin-stdlib:$kotlin_ver”
testCompile “org.jetbrains.kotlin:kotlin-test-junit:$kotlin_ver”
}

Another important detail in build.gradle is setting proper source sets to make Kotlin tests folders visible to compiler and IDE.

Source: How to do Android Testing using Kotlin

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s