When I am trying run a simple test I get java.lang.NoSuchMethodError exception for ch.qos.logback.classic.encoder.PatternLayoutEncoder.encode method in ReporterLogAppender.
I have a standard grails 3.3.x project. Just to make sure there is no conflict with the logback library dependency I have explicitly added the following to my build.gradle
compile 'ch.qos.logback:logback-classic:1.2.3'
Below is my feature file
Feature: User Management testing
Scenario: Home Page
Given url 'http://localhost:9080/um'
When method get
Then status 200
Here is the full stack trace.
java.lang.NoSuchMethodError: ch.qos.logback.classic.encoder.PatternLayoutEncoder.encode(Ljava/lang/Object;)[B
at com.intuit.karate.cucumber.ReporterLogAppender.append(ReporterLogAppender.java:72)
at com.intuit.karate.cucumber.ReporterLogAppender.append(ReporterLogAppender.java:38)
at ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:82)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.warn(Logger.java:688)
at com.intuit.karate.ScriptContext.<init>(ScriptContext.java:135)
at com.intuit.karate.StepDefs.<init>(StepDefs.java:81)
at com.intuit.karate.cucumber.KarateObjectFactory.getInstance(KarateObjectFactory.java:80)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at com.intuit.karate.cucumber.CucumberUtils.runStep(CucumberUtils.java:139)
at com.intuit.karate.cucumber.KarateRuntime.runStep(KarateRuntime.java:80)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at com.intuit.karate.junit4.Karate.runChild(Karate.java:118)
at com.intuit.karate.junit4.Karate.runChild(Karate.java:33)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at com.intuit.karate.junit4.Karate.run(Karate.java:127)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at ✽.Given url 'http://localhost:9080/um'(user-get.feature:4)
@bAmrish clearly a logback conflict. try forcing logback-core also to 1.2.3
testCompile 'ch.qos.logback:logback-classic:1.2.3'
testCompile 'ch.qos.logback:logback-core:1.2.3'
edit: this is a very common issue for those who mix Karate into existing Gradle / Maven projects:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
@ptrthomas I tried adding the gradle dependencies but it did not help. I was however able to figure out that this happens only when there is an error in parsing response from the server or a test failure. I am assuming its related to issue #259. Also I have seen this happen only when I run it using JUnit.
For now I have moved on to using cucumber runner which is much easier than Junit.
You may need to exclude some maven dependencies. Did you try analyzing the output of mvn dependency:tree. And can you do me a favor and confirm that you still see this problem with the latest (un-official) version 0.6.2.3
And are you saying you don't get this issue when using the CucumberRunner for the same feature ? Which is strange. Would be great if you can give me enough info to replicate, such as a simple feature I can run using JUnit. But I'm pretty sure it works fine in my env, and you have some other libraries. This can happen if you have something that initializes logback before Karate gets control.
Most helpful comment
@bAmrish clearly a
logbackconflict. try forcinglogback-corealso to 1.2.3edit: this is a very common issue for those who mix Karate into existing Gradle / Maven projects: