【问题标题】:how to pass parameters to a test case while running it using Junit Suite如何在使用 Junit Suite 运行测试用例时将参数传递给测试用例
【发布时间】:2019-02-21 19:32:54
【问题描述】:

我想运行我在一个包中创建的多个 Junit 测试。每个测试都需要区域和服务器参数来加载正确的数据文件。我正在使用 System.getProperty 获取所有 junit 测试的区域和服务器详细信息。我不确定如何在 TestSuite Runner 中传递这些参数。这是我创建的测试用例

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ExpenseTests {
    private static String server = System.getProperty("server");
    private static String region = System.getProperty("region");

    @BeforeClass
    public static void setup() throws Exception {
        SetUp setUp = new SetUp(region, server);
        Login(region, server);
        CreateClient(region, server);
    }
    @Test
    public void test1_checkexpense() {
     // code here
    }

    @Test
    public void test2_addbasicExpense() {
       //code here
    }
    @AfterClass
    public static void teardown() throws Exception {
       quit(webpage);
    }
}

这里是测试套件

@RunWith(Suite.class)
    @Suite.SuiteClasses({
            ExpenseTests.class
            AnotherTest.class
})
    public class SmokeTestSuite {


        }

我可以使用 mvn install -Dtest="ExpenseTests" -Dserver="prod" -Dregion="us" 运行 ExpenseTest,但是如何在上面的 SmokeTestSuite 中传递区域和服务器详细信息?

【问题讨论】:

    标签: selenium junit maven-surefire-plugin junit-runner


    【解决方案1】:

    我认为您可以使用全局变量将参数传递给所有测试用例。

    例子

    public static String server = System.getProperty("server");
    public static String region = System.getProperty("region");
    

    然后将其传递给所有测试用例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多