空手道@RunWith(Karate.class)投掷错误

时间:2018-01-31 23:20:20

标签: testing automation logback karate

当我使用@RunWith(Karate.class)运行我的功能时,我看到以下错误

我找到了一个与Junit一起运行的选项,但是没有生成空手道报告。我的所有测试用例都没有任何问题,但我希望与空手道一起运行,以便我得到很好的报告。

@RunWith(SpringRunner.class)
@CucumberOptions(tags = "~@ignore")
public class RestServicesDmaTestApplicationTests {

    @Test
    public void testABC(){
        CucumberRunner.runFeature(getClass(), "/features/ABC.feature",new HashedMap(),true);
    }
}

当我和空手道一起跑时,我的误差低于此值。

@RunWith(Karate.class)
@CucumberOptions(tags = "~@ignore",features = {"classpath:com/mastercard/send/features/ABC.feature})
public class KarateJunitTest {

    @BeforeClass
    public static void before() {
        System.setProperty("karate.env", "stage");
    }    
}



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_1(Logger.java:398)
            at ch.qos.logback.classic.Logger.info(Logger.java:583)
            at com.intuit.karate.ScriptBridge.log(ScriptBridge.java:164)
            at jdk.nashorn.internal.scripts.Script$Recompilation$5$18$\^eval\_.config(<eval>:7)
            at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
            at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
            at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
            at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:110)
            at com.intuit.karate.Script.evalFunctionCall(Script.java:1532)
            at com.intuit.karate.Script.call(Script.java:1489)
            at com.intuit.karate.Script.callAndUpdateConfigAndAlsoVarsIfMapReturned(Script.java:1606)
            at com.intuit.karate.ScriptContext.<init>(ScriptContext.java:131)
            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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
            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:237)
            at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:497)
            at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

我在类路径中看到下面的两个JAR。经典和代码jar版本都是相同的。

ch\qos\logback\logback-classic\1.1.11\logback-classic-1.1.11.jar;
ch\qos\logback\logback-core\1.1.11\logback-core-1.1.11.jar;

以下是我的POM文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test.send</groupId>
    <artifactId>rest-services-regression-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>rest-services-regression-test</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>-->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-apache</artifactId>
            <version>0.6.2</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-junit4</artifactId>
            <version>0.6.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>3.14.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.gdata</groupId>
            <artifactId>core</artifactId>
            <version>1.47.1</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
            <version>2.8.10</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.3</version>
        </dependency>

    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

1 个答案:

答案 0 :(得分:2)

发现了这个问题。似乎空手道中的logback版本不正确。

ch.qos.logback.classic.encoder.PatternLayoutEncoder.encode方法在1.1.11版本的logback中不可用。

我已经从空手道中排除了logback jar并添加了logback版本1.2.3并且它开始工作了。

    <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-apache</artifactId>
            <version>0.6.2</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.3</version>
        </dependency>