garima
garima

Reputation: 111

how to pass parameters to a test case while running it using Junit Suite

I want to run multitple Junit tests i have created in a package. Every test needs region and server paramter to load the correct data files. I am using System.getProperty to fetch region and serverdetails for all junit tests. I am not sure how to pass these parameters in a TestSuite Runner. Here is the test case i have created

@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);
    }
}

Here is the TestSuite

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


        }

I can run ExpenseTest using mvn install -Dtest="ExpenseTests" -Dserver="prod" -Dregion="us" but how do i pass region and server details in above SmokeTestSuite?

Upvotes: 0

Views: 260

Answers (1)

Mr.Kim
Mr.Kim

Reputation: 176

I think you may use Global variable to pass parameter to all test cases.

Example

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

Then pass it to all test cases.

Upvotes: 1

Related Questions