【问题标题】:How to execute java class and the run all the suite.xml files using POM.xml如何使用 POM.xml 执行 java 类并运行所有 suite.xml 文件
【发布时间】:2023-03-04 15:12:01
【问题描述】:

我们有一个 java 主类,它将从 excel 中读取输入数据并在 ExecutionSuites 文件夹中生成多个 suite.xml 文件。 (.xml 的总数取决于 excel 中提供的输入)

我想先执行 java 主类,然后使用 pom 执行这些 suiteXmlFiles。

提前致谢!

【问题讨论】:

  • 我试过下面的代码,但它在执行过程中没有运行 java 主类 1: src.test.java.Package1.mainClass1
  • 为了运行所有套件,maven-surefire-plugin 插件中的以下配置以错误结束 ExecutionSuites/ *.xml

标签: java maven selenium-webdriver appium maven-surefire-plugin


【解决方案1】:

你误会了什么。当你运行 mvn clean test. 时,main() 方法不会被surefire 执行

在运行测试时,您不希望 Class (with main) 先运行。这是您的*Test 课程的一部分。

您的主类逻辑可能是您的 @Test 方法的一部分:

public class Test1{

  @Test
  public voidTestMethod1(){
    MainClass example = new MainClass(); 
    example.loadData();
    //assert something.

  }
}

其他有用的提示:假设你想运行specific logic,在你的西装运行之前,你可以使用@BeforeSuite注解

public class MyFirstTest 
{
    @Test
    public void testCase() {
    }
 
    @BeforeSuite
    public void beforeSuite() {
        System.out.println("Before Suite method");
    }
 
    @AfterSuite
    public void afterSuite() {
        System.out.println("After Suite method");
    }
 
    @BeforeTest
    public void beforeTest() {
        System.out.println("Before Test method");
    }
     
    @AfterTest
    public void afterTest() {
        System.out.println("After Test method");
    }
     
    @BeforeClass
    public void beforeClass() {
        System.out.println("Before Class method");
    }
 
    @AfterClass
    public void afterClass() {
        System.out.println("After Class method");
    }
 
    @BeforeMethod
    public void beforeMethod() {
        System.out.println("Before Method");
    }
 
    @AfterMethod
    public void afterMethod() {
        System.out.println("After Method");
    }
}

然后您的 sunfire-plugin 将运行您的测试文件:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M5</version>
    <configuration>
      <suiteXmlFiles>
        <file>src/test/resources/testng1.xml</file>
        <file>src/test/resources/testng2.xml</file>
      </suiteXmlFiles>
      <properties>
        <property>
          <name>suitethreadpoolsize</name>
          <value>2</value>
        </property>
      </properties>
    </configuration>
  </plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 2019-06-07
    • 2020-08-14
    相关资源
    最近更新 更多