No such method error in tests (with Kotest)
See original GitHub issueI thing something is wrong between Kotest 4.2.4 and Clikt 3.0.1
Then I’m wrtiting this class in the test sources directory:
class ATestCommand : CliktCommand() {
private val environment: String? by option("-e", "--env")
override fun run() {
println("Env: $environment")
}
}
gives an intellj error on option
:
Overload resolution ambiguity:
public fun ParameterHolder.option(vararg names: String, help: String = ..., metavar: String? = ..., hidden: Boolean = ..., envvar: String? = ..., helpTags: Map<String, String> = ..., completionCandidates: CompletionCandidates? = ..., valueSourceKey: String? = ...): RawOption /* = OptionWithValues<String?, String, String> */ defined in com.github.ajalt.clikt.parameters.options
public fun ParameterHolder.option(vararg names: String, help: String = ..., metavar: String? = ..., hidden: Boolean = ..., envvar: String? = ..., envvarSplit: Regex? = ..., helpTags: Map<String, String> = ..., completionCandidates: CompletionCandidates? = ...): RawOption /* = OptionWithValues<String?, String, String> */ defined in com.github.ajalt.clikt.parameters.options
Same class in source no problem.
Noticed that while was trying to figure out why I can’t run any test on a command.
when I run the test:
class ATestCommandTest() : FunSpec({
test("test should run without throwing NoSuchMethodError") {
ATestCommand().parse(emptyArray())
}
})
I got the error:
'com.github.ajalt.clikt.parameters.options.OptionWithValues com.github.ajalt.clikt.parameters.options.OptionWithValuesKt.option$default(com.github.ajalt.clikt.core.ParameterHolder, java.lang.String[], java.lang.String, java.lang.String, boolean, java.lang.String, java.util.Map, com.github.ajalt.clikt.completion.CompletionCandidates, java.lang.String, int, java.lang.Object)'
java.lang.NoSuchMethodError: 'com.github.ajalt.clikt.parameters.options.OptionWithValues com.github.ajalt.clikt.parameters.options.OptionWithValuesKt.option$default(com.github.ajalt.clikt.core.ParameterHolder, java.lang.String[], java.lang.String, java.lang.String, boolean, java.lang.String, java.util.Map, com.github.ajalt.clikt.completion.CompletionCandidates, java.lang.String, int, java.lang.Object)'
This does not happen if I use JUnit 5 in place of Kotest.
My build.gradle.kts
(useful parts)
plugins {
application
kotlin("jvm") version "1.4.10"
}
// ...
dependencies {
implementation("com.github.ajalt.clikt:clikt:3.0.1")
implementation("com.typesafe:config:1.4.0")
testImplementation("io.kotest:kotest-runner-junit5:4.2.4") // for kotest framework
testImplementation("io.kotest:kotest-assertions-core:4.2.4") // for kotest core jvm assertions
testImplementation("io.kotest:kotest-property:4.2.4") // for kotest property test
testImplementation("io.mockk:mockk:1.10.0")
}
// ...
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "11"
}
tasks.withType<Test>() {
useJUnitPlatform()
}
// ...
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
java.lang.NoSuchMethodError: 'io.kotest.core.test ... - GitHub
Which version of Kotest are you using "io.kotest.extensions:kotest-extensions-spring:1.0.1" ... NoSuchMethodError: 'io.kotest.core.test.
Read more >Kotlin: java.lang.NoSuchMethodError in tests - Stack Overflow
When I try to do so, I have NoSuchMethodError thrown. Example. I have Gradle project with Kotlin code and two sourcesets in it,...
Read more >Fixing the NoSuchMethodError JUnit Error | Baeldung
In this article, we're going to learn how to fix the NoSuchMethodError and NoClassDefFoundError JUnit errors. Such problems usually occur ...
Read more >NoSuchMethodError (Java Platform SE 7 ) - Oracle Help Center
Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has...
Read more >Changelog - Kotest
Fix issues running tests for native targets on Kotlin 1.7+ (#3107) ... Fix regression which causes NoSuchMethodError when using the Kotest Spring extension ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another option is to bump to kotest 4.3.1 which should require no changes, and works with any version of clickt.
@sksamuel Yup, that also seems to work!