[Cucumber][JVM][Maven]测试无法通过 maven 从命令行运行

2024-03-09

我正在使用 java、cucumber 和 Maven 运行测试。 我正在使用 Eclipse IDE。 pom.xml 也具有 Cucumber 依赖项。 我以两种方式运行测试。

  1. 从 Eclipse IDE:我将测试作为 Junit 测试运行,测试结果成功。

2:从命令提示符处:我的测试失败,结果如下。

  • 这是 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: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further   details.

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building CCIRA_Test_Auto 0.0.1
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ CCIRA_Test_Auto ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\rah\Documents\workspace\CCIRA_Test_Auto\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ CCIRA_Test_Auto ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ CCIRA_Test_Auto ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\rah\Documents\workspace\CCIRA_Test_Auto\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ CCIRA_Test_Auto ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ CCIRA_Test_Auto ---
[INFO] Surefire report directory: C:\Users\rah\Documents\workspace\CCIRA_Test_Auto\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------


Results :


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

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 10.051s
    [INFO] Finished at: Mon Dec 05 09:30:10 GMT 2016
    [INFO] Final Memory: 7M/62M
    [INFO] ------------------------------------------------------------------------

依赖性

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 插件额外的类路径元素 http://maven.apache.org/surefire/maven-surefire-plugin/examples/configuring-classpath.html元素“将自定义资源/JAR 添加到您的类路径。这将被视为绝对文件系统路径,因此您可能需要使用 ${basedir} 或与相对路径组合的其他属性。请注意,其他类路径元素将添加到类路径末尾,因此您不能使用它们来覆盖项目依赖项或资源。”

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

[Cucumber][JVM][Maven]测试无法通过 maven 从命令行运行 的相关文章

随机推荐