Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Write Kotlin Unit Test with kotlin-test?

I am trying to test my code using Kotlin. When trying to import the kotlin.test package, nothing appears.

Do I have to add the dependency somewhere first? And how can I run my unit test afterwards?

like image 401
OhMad Avatar asked Jul 16 '17 17:07

OhMad


1 Answers

The kotlin.test package is packaged in kotlin-test module, so you need add the dependencies in your build.gradle as below:

dependencies{
   testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

Beside that, you need to add an unit test framework in the build.gradle like as junit-4, for example:

dependencies{
   testCompile "junit:junit:4.12"
}

How to write a JUnit Test? you can see it in junit.org as further.

like image 87
holi-java Avatar answered Oct 22 '22 05:10

holi-java