无法启动黄瓜简单测试

时间:2016-02-25 10:09:22

标签: spring maven testing cucumber

我有Spring项目。现在我尝试启动简单的黄瓜测试并得到一个错误(((我认为这是因为Spring,所以我创建了具有下一个结构的单独项目:

src/
|
| --main/
|     --java/
|        --cucumber/
|        --CucumberRunner
|        --features
|          --MyFeatures.feature
|          --StepDefinitions.java

我仍然得到同样的错误(

Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 28 more

我的跑步者:

@RunWith(Cucumber.class)
@CucumberOptions(
        format ={"pretty", "json:target/cucumber.json"},
        features = {"src/main/java"}
)
public class CucumberRunner {

}

我知道路径不正确但我尝试了所有可能的组合 - 结果是一样的((( 我的特色:

Feature: Testing my simple kickstarter project

  Scenario: My first test
    Given I navigate to Categories page
    When When I enter 'f'
    Then Error is displayed

我的步骤:

public class StepDefinitions {
    @Given("^I navigate to Categories page$")
    public void i_navigate_to_Categories_page() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @When("^When I enter 'f'$")
    public void when_I_enter_f() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @Then("^Error is displayed$")
    public void error_is_displayed() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }
}

我的pom.xml文件:

<?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 ht

tp://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<groupId>cucumber</groupId>
<artifactId>cucumber</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <!--Cucumber jars-->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.1.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.1.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.1.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.1.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.1.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.3</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-html</artifactId>
        <version>0.2.3</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.1</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>2.42.0</version>
    </dependency>
</dependencies>

提供帮助。我检查了谷歌 - 没有错误的结果((

修改 mvn依赖的结果:tree:

[INFO] cucumber:cucumber:jar:1.0-SNAPSHOT
[INFO] +- info.cukes:cucumber-java:jar:1.1.5:compile
[INFO] +- info.cukes:cucumber-testng:jar:1.1.5:compile
[INFO] |  \- org.testng:testng:jar:6.8.7:compile
[INFO] |     +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] |     \- com.beust:jcommander:jar:1.27:compile
[INFO] +- info.cukes:cucumber-junit:jar:1.1.5:compile
[INFO] |  \- junit:junit:jar:4.11:compile
[INFO] |     \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- info.cukes:cucumber-core:jar:1.1.5:compile
[INFO] +- info.cukes:cucumber-jvm-deps:jar:1.0.3:compile
[INFO] +- info.cukes:cucumber-html:jar:0.2.3:compile
[INFO] +- info.cukes:gherkin:jar:2.12.1:compile
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:compile
[INFO] \- org.seleniumhq.selenium:selenium-server:jar:2.42.0:compile
[INFO]    +- org.bouncycastle:bcprov-jdk15on:jar:1.48:compile
[INFO]    +- org.bouncycastle:bcpkix-jdk15on:jar:1.48:compile
[INFO]    +- mx4j:mx4j-tools:jar:3.0.1:compile
[INFO]    +- org.mortbay.jetty:servlet-api-2.5:jar:6.1.9:compile
[INFO]    +- org.seleniumhq.selenium:jetty-repacked:jar:7.6.1:compile
[INFO]    +- net.jcip:jcip-annotations:jar:1.0:compile
[INFO]    +- org.seleniumhq.selenium:selenium-java:jar:2.42.0:compile
[INFO]    |  +- org.seleniumhq.selenium:selenium-chrome-driver:jar:2.42.0:compile
[INFO]    |  |  \- org.seleniumhq.selenium:selenium-remote-driver:jar:2.42.0:compile
[INFO]    |  |     +- cglib:cglib-nodep:jar:2.1_3:compile
[INFO]    |  |     +- org.json:json:jar:20080701:compile
[INFO]    |  |     \- com.google.guava:guava:jar:15.0:compile
[INFO]    |  +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.42.0:compile
[INFO]    |  |  +- net.sourceforge.htmlunit:htmlunit:jar:2.14:compile
[INFO]    |  |  |  +- xalan:xalan:jar:2.7.1:compile
[INFO]    |  |  |  |  \- xalan:serializer:jar:2.7.1:compile
[INFO]    |  |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO]    |  |  |  +- org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO]    |  |  |  +- org.apache.httpcomponents:httpmime:jar:4.3.2:compile
[INFO]    |  |  |  +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.14:compile
[INFO]    |  |  |  +- xerces:xercesImpl:jar:2.11.0:compile
[INFO]    |  |  |  |  \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO]    |  |  |  +- net.sourceforge.nekohtml:nekohtml:jar:1.9.20:compile
[INFO]    |  |  |  +- net.sourceforge.cssparser:cssparser:jar:0.9.13:compile
[INFO]    |  |  |  |  \- org.w3c.css:sac:jar:1.3:compile
[INFO]    |  |  |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO]    |  |  |  \- org.eclipse.jetty:jetty-websocket:jar:8.1.14.v20131031:compile
[INFO]    |  |  |     +- org.eclipse.jetty:jetty-util:jar:8.1.14.v20131031:compile
[INFO]    |  |  |     +- org.eclipse.jetty:jetty-io:jar:8.1.14.v20131031:compile
[INFO]    |  |  |     \- org.eclipse.jetty:jetty-http:jar:8.1.14.v20131031:compile
[INFO]    |  |  \- org.apache.httpcomponents:httpclient:jar:4.3.2:compile
[INFO]    |  |     \- org.apache.httpcomponents:httpcore:jar:4.3.1:compile
[INFO]    |  +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.42.0:compile
[INFO]    |  |  +- commons-io:commons-io:jar:2.4:compile
[INFO]    |  |  \- org.apache.commons:commons-exec:jar:1.1:compile
[INFO]    |  +- org.seleniumhq.selenium:selenium-ie-driver:jar:2.42.0:compile
[INFO]    |  |  +- net.java.dev.jna:jna:jar:3.4.0:compile
[INFO]    |  |  \- net.java.dev.jna:platform:jar:3.4.0:compile
[INFO]    |  +- org.seleniumhq.selenium:selenium-safari-driver:jar:2.42.0:compile
[INFO]    |  +- org.seleniumhq.selenium:selenium-support:jar:2.42.0:compile
[INFO]    |  |  \- org.seleniumhq.selenium:selenium-api:jar:2.42.0:compile
[INFO]    |  \- org.webbitserver:webbit:jar:0.4.14:compile
[INFO]    |     \- io.netty:netty:jar:3.5.2.Final:compile
[INFO]    +- org.yaml:snakeyaml:jar:1.8:compile
[INFO]    \- commons-codec:commons-codec:jar:1.9:compile

编辑:添加下一个库后:

<dependency>
            <groupId>org.ogce</groupId>
            <artifactId>xpp3</artifactId>
            <version>1.1.5</version>
        </dependency>
        <dependency>
            <groupId>org.jdom</groupId>
            <artifactId>jdom</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>xom</groupId>
            <artifactId>xom</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.woodstox</groupId>
            <artifactId>wstx-lgpl</artifactId>
            <version>3.2.6</version>
        </dependency>
        <dependency>
            <groupId>stax</groupId>
            <artifactId>stax</artifactId>
            <version>1.2.0</version>
        </dependency>

最后我可以编译它,但我的功能文件仍然无法看到步骤((

Test ignored.
Test ignored.
Test ignored.
Test ignored.
Test ignored.
Test ignored.Feature: Testing my simple kickstarter project

  Scenario: My first test               # features/myFeatures.feature:3
    Given I navigate to Categories page
    When When I enter 'f'
    Then Error is displayed

1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s


You can implement missing steps with the snippets below:
....

1 个答案:

答案 0 :(得分:0)

您收到此错误是因为您错过了XML Pull parser library。您可以在POM中添加一个with the following dependency。您还需要添加Jdom库

<dependency>
    <groupId>org.ogce</groupId>
    <artifactId>xpp3</artifactId>
    <version>1.1.5</version>
</dependency>
<dependency>
    <groupId>org.jdom</groupId>
    <artifactId>jdom</artifactId>
    <version>2.0.2</version>
</dependency>