当前位置: 首页 > 知识库问答 >
问题:

如何使用Maven POM文件运行testNG测试

柯鸿振
2023-03-14

我有一个Selenium项目,使用Maven和TestNG。

我已经尝试了几种不同的方法来使用Maven命令运行测试(我使用的是sure fire插件)。当我运行Maven时,测试不会运行。没有错误。

有没有人有一个很好的例子或教程,我可以遵循使我的测试运行时,我使用mvn测试?

提前道谢。

以下是输出:

C:\**************>mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - **************:**************:jar:1.0
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\**************\src\test\res
ources
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Oct 02 15:14:10 BST 2012
[INFO] Final Memory: 16M/38M
[INFO] ------------------------------------------------------------------------

和POM文件中的surefire配置:

<plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>iso-8859-1</encoding>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>src/main/test_suites/local/***_Test.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

共有1个答案

庄康胜
2023-03-14

看看这个Maven Using TestNG站点。

基本上,您所要做的就是向testng添加一个依赖项。

<dependencies>
  [...]
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.3.1</version>
      <scope>test</scope>
    </dependency>
  [...]
</dependencies>

maven-surefire-plugin中的默认值包括:

<includes>
    <include>**/Test*.java</include>
    <include>**/*Test.java</include>
    <include>**/*TestCase.java</include>
</includes>

这意味着,如果您的测试类的名称与上面的include模式不匹配,那么maven-surefire-plugin将无法找到它们并运行它们。

您可以通过将这些文件添加到插件配置中来更改/添加要包含的文件。

 类似资料:
  • 试图实现硒cucumber测试而不是JUnit。 我的疑问是 testng中@Runwith(Cucumber.class)的替代选项是什么

  • 你能帮助我有没有什么方法运行空手道跑者文件与TestNG框架工作。你的答案真的会让我们做出决定。 我经历了各种与空手道相关的测试的帖子。但不幸的是我无法触发我的脚本。 注意:我在代码中扩展了KarateRunner类并使用了@KarateOptions。

  • 我有一个testng xml文件,它被设置为运行一个特定的类,该类的方法包含以下组标记或被分组为以下类型之一: 并行测试 顺序测试 烟雾测试 虽然我的一些测试被指定为并行或顺序测试,但一些测试可能包含一个额外的标签“冒烟测试”。在这个场景中,我希望能够只运行那些被归类为“烟雾测试”的组件。当我运行测试时,它要么找不到任何测试,要么只是运行所有分组为“sequential-test”的测试。我似乎不

  • 我有一个关于testNG的问题。我有五类测试(a类、b类、c类、d类、e类),并且在每个类中都有3个测试(test1 test2 test3)问题是我在所有测试中都有@Test(组={"吸烟测试"},启用=真,优先级=1)-类a-类a-类a <代码>@测试(组={"吸烟测试"},启用=真,优先级=1) -类b<代码>@测试(组={"吸烟测试"},启用=真,优先级=2) -类b<代码>@测试(组={

  • 请让我知道是否可以通过TestNG运行并行套件?

  • 问题内容: 我想使用Jenkins运行用TestNG框架编写的Selenium测试。 在jenkins job(Freestyle project)中配置的命令: 注意:对于,给定目录路径 当我运行作业(选项)时,它被Selenium的create session活动打中并给出错误。 注意: 同样的命令运行 成功地 从运行时 的命令行 。 控制台输出的错误日志: (jenkins) 以下是测试课程