Published on

Kotlin Const Vals and Kotlin Unit Tests in IntelliJ


Today I had to make changes to Kotlin code I was working on. The test for this code has a helper class with const vals for common constants used in the test. The change I made to the code required me to change these consts. The weird thing is I changed these values and could not work out why the test was failing despite the fact that I had updated these consts to reflect the changes I made.

Eventually I thought let me try mvn clean install the code first then run the test. Lo and behold the tests passed!

I suspect what may be happening is that as const vals are compile time constants there may be a bug in the version of IntelliJ (IntelliJ IDEA 2017.3.2 (Ultimate Edition)) I am using where these compile time constants are not recompiled by IntelliJ when running tests from the IDE. Googling this issue I could not find any related bugs online. Luckily I am on an older version of the IDE, I will try update to a newer version and see if this issue has been sorted.