【问题标题】:Is there a way to tell maven which testClass it should execute有没有办法告诉 maven 它应该执行哪个 testClass
【发布时间】:2019-03-01 15:33:50
【问题描述】:

这是我的问题。

我正在使用具有这么多 testClass 的单个项目

--Package
----TestClass1
----TestClass2
----TestClass3

每个testClass 都是一个测试套件,包含它自己的beforeTesttestafterTest 注释

我想实现和 testClass 一样多的 jenkins jonbs

现在我唯一的虚拟解决方案是复制项目并为每个作业创建一个 testClass。

有没有办法让 maven 用它的名字来指向一个类,或者类似的东西?有点像mvn clean test -D=className

对不起我的英语

【问题讨论】:

    标签: java maven jenkins


    【解决方案1】:

    您可以将命令行属性surefire.includesFile 设置为一个文件,在该文件中列出相关的类。另请参阅

    https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html

    您应该在哪里寻找“includesFile”。

    【讨论】:

    • 谢谢 我如何配置我的 jenkins 以使用 surefire 执行正确的类?执行命令有什么要补充的吗?
    【解决方案2】:

    您可以将测试名称作为 maven 参数的一部分传入,即

    -Dtest=TestClass1, TestClass3 测试

    运行 TestClass1 和 TestClass3

    找到更多示例@How to run multiple test classes or test methods using Maven?

    【讨论】:

      【解决方案3】:

      为特定的测试类创建一个 TestClass1.xml 文件。

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
      <suite name="Suite">
        <test name="Test">
          <classes>
            <class name="com.tutorial.testng.TestClass1"/>
          </classes>
        </test>
      </suite>
      

      现在在 'maven-surefire-plugin' 中使用动态 xml 文件名,如下所述。

      <configuration>
      
              <suiteXmlFiles>
      
                  <!-- TestNG suite XML files -->
               <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
      
              </suiteXmlFiles>
      
      
      </configuration>
      

      现在你可以使用通过 maven 运行它了

      mvn clean test -Dsurefire.suiteXmlFiles=TestClass1.xml
      

      在 Jenkins 中,您可以使用“使用参数构建”创建作业并创建字符串参数。现在您可以在 Jenkins 中传递 testng.xml。查看下面的操作方法。

      https://www.theserverside.com/video/Modify-CI-jobs-with-this-Jenkins-parameterized-build-example

      希望它会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-19
        • 1970-01-01
        • 2017-03-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-14
        • 2011-07-28
        • 1970-01-01
        相关资源
        最近更新 更多