0

要从命令提示符运行 testng 测试,我必须设置类路径并运行测试 C:\newworkspace\SeleniumSample>set classpath = C:\newworkspace\SeleniumSample\bin; C:\newworkspace\SeleniumSample\lib*

C:\newworkspace\SeleniumSample>java org.testng.TestNG testng.xml

我的 maven 项目不包含 bin 或 lib 文件夹。我手动创建了 lib 文件夹并将 jars 添加到该文件夹​​中。任何帮助都会很棒。

4

1 回答 1

1

Maven 没有 bin 文件夹,因为 POM 文件中提到的所有依赖 JAR 文件都已下载并保存在 ${user.home}/.m2 文件夹中。如果您想从命令行触发 TestNG 测试用例,您可以通过在 POM 中配置插件来使用用于 TestNG 的 Maven Surefire 插件。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <failIfNoTests>true</failIfNoTests>
                <skipTests>false</skipTests>
                <suiteXmlFiles>
                    <suiteXmlFile>${testNGXMLFile}</suiteXmlFile>
                </suiteXmlFiles>
                <properties>
                    <property>
                        <name>usedefaultlisteners</name>
                        <value>true</value>
                    </property>
                </properties>
                <workingDirectory>${basedir}</workingDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

然后在命令提示符下,您可以使用 maven 触发

mvn clean test -DtestNGXMLFile=src\test\resources\testng.xml

有关用于 testng 的 apache maven-surefire-plugin 的更多信息

于 2020-02-11T05:47:29.233 回答