Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extension function not found when run tests

I have this extension:

src/main/kotlin/com/myproject/api/extensions.kt

fun String.asJson() : JsonObject {
    return JsonObject.readFrom(this)
}

When I run my application, it works fine. But, when I run a test case that uses that extension function, it crashes:

java.lang.NoSuchMethodError: com.myproject.api.ExtensionsKt.asJson(Ljava/lang/String;)Lcom/eclipsesource/json/JsonObject;

What am I missing?

like image 716
Héctor Avatar asked Aug 16 '18 15:08

Héctor


1 Answers

After hours, I finally found the error. I already had a extensions.kt file in the same package but in test directory! src/test/kotlin/com/myproject/api/extensions.kt. I changed the name to testExtensions.kt and everything is working now.

like image 84
Héctor Avatar answered Sep 24 '22 15:09

Héctor