【问题标题】:Test running as expected from intelliJ IDE but not when running it from the command line TestNG测试从 IntelliJ IDE 中按预期运行,但从命令行 TestNG 运行时没有
【发布时间】:2020-06-29 14:41:38
【问题描述】:

当我直接从 intelliJ IDE 测试按预期运行时,我尝试使用 Maven 从命令行运行我的测试,当我尝试运行然后使用 mvn test 时,我收到以下消息:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@34c4973
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2020-06-29 17:32:49 [ERROR]failed to create 'BaseTest-531000' directory
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.99 sec

Results :

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

这是我的 POM.xml:


    <modelVersion>4.0.0</modelVersion>
    <groupId>com.takeaway.automation</groupId>
    <artifactId>takeaway-project</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <java.version>1.8</java.version>
        <testng.version>7.1.0</testng.version>
        <awaitility.version>3.0.0</awaitility.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.12</version>
        </dependency>     
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-configuration2 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-configuration2</artifactId>
            <version>2.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.8</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
            <version>2.10.3</version>
        </dependency>
    </dependencies>

</project>

我的测试在类名下是 HTTPTester.java 在那里我得到了我所有的 testng 测试用例:

 src/testjava/com/takeaway/automation/tests/api/HTTPTester.java

【问题讨论】:

    标签: java maven testng


    【解决方案1】:

    除非您另外配置,否则surefire maven 插件会期望您的测试在:

    src/test/java/com/takeaway/automation/tests/api/HTTPTest.java
    

    src/test/java,不是src/testjava*Test.java 不是*Tester.java

    在此处查看更多详细信息:https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

    【讨论】:

    • 据你了解,我确实将测试类放在了正确的位置,但它仍然没有运行......
    【解决方案2】:

    好的,我找到了缺少的东西,添加 'maven-surefire-plugin' 插件丢失了:

     <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <includes>
                            <include>HTTPTester.java</include>
                        </includes>
                    </configuration>
                </plugin>
    

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      相关资源
      最近更新 更多