【问题标题】:Can't run TestNG with custom class name from command line with Maven无法使用 Maven 从命令行使用自定义类名运行 TestNG
【发布时间】:2020-12-17 03:54:37
【问题描述】:

我在 Intellij IDEA 上使用 Selenium 插件和 Maven 和 TestNG。我正在尝试使用“mvn clean test”从命令行运行我的项目。当我创建一个带有“MainPageTest.java”作为测试类的新项目时,此命令可以正常工作。当我将类/文件名更改为“Runner.java”或其他任何内容时,我可以从 IDE 运行它,但不能从命令行运行它。 这是它工作时的线程。

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ demo ---
[INFO] Deleting C:\Users\Admin\IdeaProjects\demo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Admin\IdeaProjects\demo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Admin\IdeaProjects\demo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Admin\IdeaProjects\demo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Admin\IdeaProjects\demo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.MainPageTest

// WebDriver related stuff

[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.200 s
[INFO] Finished at: 2020-12-16T22:42:10-05:00
[INFO] --------------------------------------

这是我更改班级名称的时候:

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ demo ---
[INFO] Deleting C:\Users\Admin\IdeaProjects\demo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Admin\IdeaProjects\demo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Admin\IdeaProjects\demo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Admin\IdeaProjects\demo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Admin\IdeaProjects\demo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.076 s
[INFO] Finished at: 2020-12-16T22:47:44-05:00
[INFO] ------------------------------------------------------------------------

如您所见,没有错误,但它没有运行测试。我已经尝试重建项目,运行 mvn clean install,并添加一个 testng.xml 文件,但没有任何效果,并且在项目/配置中的其他任何地方都没有提到 MainPageTest。有人请帮忙。谢谢。

【问题讨论】:

    标签: java selenium maven intellij-idea testng


    【解决方案1】:

    我想通了,我所做的只是在我的 pom.xml 中指定我的 testng.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="All Test Suite">
        <test verbose="2" preserve-order="true" name="C:/Users/Admin/IdeaProjects/demo">
            <classes>
                <class name="com.example.demo.Runner">
                    <methods>
                        <include name="test1"/>
                        <include name="test2"/>
                        <include name="test3"/>
                        <include name="test4"/>
                    </methods>
                </class>
            </classes>
        </test>
    </suite>
    
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <testFailureIgnore>true</testFailureIgnore>              
        <suiteXmlFiles>
            <!-- TestNG suite XML files -->
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 2012-05-10
      • 2018-08-05
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      相关资源
      最近更新 更多