Java Maven项目测试可以';t Find cumber测试以在命令行上运行特性测试(适用于cumber)

Java Maven项目测试可以';t Find cumber测试以在命令行上运行特性测试(适用于cumber),java,maven,cucumber,Java,Maven,Cucumber,在这里的第一篇文章中,我一直在寻找解决我问题的方法。我正试图在我的Cucumber测试示例上通过maven运行一个测试。mvn测试没有拾取steps文件(在我定义了Runner测试文件feature=…)中的位置之后),而是在命令行中提供代码段声明。我还想提到,当我运行该功能文件时,它在eclipse中运行得非常好 这是我的结构 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2

在这里的第一篇文章中,我一直在寻找解决我问题的方法。我正试图在我的Cucumber测试示例上通过maven运行一个测试。mvn测试没有拾取steps文件(在我定义了Runner测试文件feature=…)中的位置之后),而是在命令行中提供代码段声明。我还想提到,当我运行该功能文件时,它在eclipse中运行得非常好

这是我的结构

<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>edu.mason</groupId>
    <artifactId>Cucumber</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Cucumber</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

这是我的mvn测试

$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Cucumber 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Cucumber ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Johnny\workspace\Cucumber\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Cucumber ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Cucumber ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Johnny\workspace\Cucumber\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Cucumber ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\Johnny\workspace\Cucumber\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Cucumber ---
[INFO] Surefire report directory: C:\Users\Johnny\workspace\Cucumber\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running edu.mason.Cucumber.CucumbRunnerTest

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


You can implement missing steps with the snippets below:

@Given("^I have value in an account$")
public void i_have_value_in_an_account() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I deduct money from a bank account$")
public void i_deduct_money_from_a_bank_account() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I will verify the deduction has occured correctly$")
public void i_will_verify_the_deduction_has_occured_correctly() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

Tests run: 5, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 1.692 sec

Results :

Tests run: 5, Failures: 0, Errors: 0, Skipped: 4

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.329 s
[INFO] Finished at: 2016-09-29T15:19:46-07:00
[INFO] Final Memory: 14M/194M
[INFO] ------------------------------------------------------------------------
package edu.mason.Cucumber;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/resource")
public class CucumbRunnerTest {

}
Pom文件

<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>edu.mason</groupId>
    <artifactId>Cucumber</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Cucumber</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
黄瓜步骤

package cucumb.features;

import static org.junit.Assert.*;


import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;


public class CucumbSteps {
    int balance = 3000;

    @Given("^I have value in an account$")
    public void valueCheck(){
        System.out.println("Your balance is: "+balance);
    }
    @When("^I deduct money from a bank account$")
    public void stealMoney(){
        balance-=2999;
        System.out.println("Money has succesfully be stolen!!!" + balance);
    }
    @Then("^I will verify the deduction has occured correctly$")
    public void verifyStolen(){
        System.out.print("If money is stolen successfully, assert will be true (1) ");
        assertTrue(balance==1);
    }

}

指定指向steps包位置的胶水

@CucumberOptions(features="src/test/resource", glue = "cucumb.features")

我将其移动并将RunnerTest更新到该目录,我得到了相同的错误。谢谢