首页 文章

[Cucumber] [JVM] [Maven]测试不能从命令行运行到maven

提问于
浏览
0

我正在使用java,黄瓜和Maven运行测试 . 我正在使用Eclipse IDE . pom.xml也有黄瓜依赖 . 我正在以两种方式运行测试 .

  • 来自Eclipse IDE:我将测试作为Junit测试运行,测试结果成功 .

2:来自命令promt:我的测试失败,下面是结果 .

  • 这是Pom.xml:

http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0

<groupId>CCIRA_Test_Auto</groupId>
<artifactId>CCIRA_Test_Auto</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>CCIRA_Test_Auto</name>

<properties>
    <cucumber.version>1.2.0</cucumber.version>
    <picocontainer.version>2.15</picocontainer.version>
</properties>

<dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.2.1</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.44.0</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.11-beta3</version>
    </dependency>
    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>2.0.2</version>
    </dependency>

    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.8.0</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
  • 我的跑步者测试:

包ccira.helpers;

import org.junit.runner.RunWith;



import org.testng.annotations.Test;

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



@RunWith(Cucumber.class)

@CucumberOptions(

features = "C:/Users/rah/Documents/workspace/CCIRA_auto/src/ressouces/features",

tags = {"@Personne"},

glue={"ccira.stepDefinitions"},

plugin ={
"pretty",
"html:results/cucumber",
"json:results/cucumber.json",
"junit:results/cucumber.xml",
}
        )


public class RunnerTest {
}
  • 我的输出控制台:

SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder” .

SLF4J:默认为无操作(NOP) Logger 实现

SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder .

[INFO]扫描项目......
[信息]
[INFO] ----------------------------------------------- -------------------------
[INFO] Build CCIRA_Test_Auto 0.0.1
[INFO] ----------------------------------------------- -------------------------
[警告]工件xml-apis:xml-apis:jar:2.0.2已重新定位到xml-apis:xml-apis:jar:1.0.b2
[信息]
[INFO] --- maven-resources-plugin:2.5:资源(默认资源)@ CCIRA_Test_Auto ---
[debug]执行contextualize
[警告]使用平台编码(实际上是Cp1252)来复制过滤后的资源,即构建依赖于平台!
[INFO]跳过不存在的resourceDirectory C:\ Users \ rah \ Documents \ workspace \ CCIRA_Test_Auto \ src \ main \ resources
[信息]
[INFO] --- maven-compiler-plugin:2.3.2:compile(default-compile)@ CCIRA_Test_Auto ---
[INFO]无需编译 - 所有课程都是最新的
[信息]
[INFO] --- maven-resources-plugin:2.5:testResources(default-testResources)@ CCIRA_Test_Auto ---
[debug]执行contextualize
[警告]使用平台编码(实际上是Cp1252)来复制过滤后的资源,即构建依赖于平台!
[INFO]跳过不存在的resourceDirectory C:\ Users \ rah \ Documents \ workspace \ CCIRA_Test_Auto \ src \ test \ resources
[信息]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile(default-testCompile)@ CCIRA_Test_Auto ---
[INFO]无需编译的来源
[信息]
[INFO] --- maven-surefire-plugin:2.10:test(default-test)@ CCIRA_Test_Auto ---
[INFO] Surefire报告目录:C:\ Users \ rah \ Documents \ workspace \ CCIRA_Test_Auto \ target \ surefire-reports


T E S T S.


结果:

测试运行:0,失败:0,错误:0,跳过:0

[INFO] ----------------------------------------------- -------------------------
[信息] Build 成功
[INFO] ----------------------------------------------- -------------------------
[INFO]总时间:10.051秒
[INFO]完成于:2016年12月5日星期一09:30:10 GMT
[INFO]最终记忆:7M / 62M
[INFO] ----------------------------------------------- -------------------------

2 回答

  • 0

    尝试从命令提示符处使用以下命令运行

    mvn clean test -Dcucumber.options="src/resources/features --tags @@Personne"

  • 1

    依赖性

    org.slf4j.impl.StaticLoggerBinder
    

    未在您的pom.xml文件中定义 . 但是,它在Eclipse项目的构建路径中定义 . 在类路径上放置一个(并且只有一个)slf4j-nop.jar,slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或logback-classic.jar应该可以解决问题 .

    我会在你的pom.xml中添加一个依赖项,可能是这样的:

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>
    

    EDIT

    一个不太好但可行的替代方案是使用Surefire插件的additionalClasspathElements元素"to add custom resources/JARs to your classpath. This will be treated as an absolute file system path, so you may want use $ or another property combined with a relative path. Note that additional classpath elements are added to the end of the classpath, so you cannot use these to override project dependencies or resources."

    我说不太好,因为最好跟踪pom.xml中的依赖项,如果你将一个依赖项更新到更高版本,你可以看到其他依赖项也必须更新 . 您可能会忽略在surefire插件中指定的jar .

相关问题