Testng parallel execution fails due to variable value mismatch

28 Views Asked by At

I am writing tests for my apis using testng in parallel. I have also used dataprovider to data insertion. But while running in parallel, my assertions failing due to mismatch where as api response is correct but its the data provider which is returning the value. Example

@Test(groups = {
            "QA-CRE", "Regression", "BuildVerification"}, priority = 86,
            dataProvider = "listC",
            dataProviderClass = country.class)
    public void test1(String usecase) throws IOException {

        this.responseData = coreRestapi(cspUid, readExcel(TEST_DATA_PATH, 3, 9, 1), usecase);

        if (this.responseData.getStatusCode() == 200) {
            this.responseData.then().
                    assertThat()
                    //fails here where as api response matches while coming from data provider to usecase but here it fails
                    .body("usecase", equalTo(usecase));
        } else {
            Assert.fail("");
        }
   }
   

@DataProvider(name = "listC")
    public static Object[][] listC() {
        return new Object[][]{
                {
                        "USA"
                },
                {
                        INDIA.toString()
                },
        };
    }

So as per my debug, it works fine in sending right usecase and like wise response comes from the server but while assertion it fails. What could be the reason and also how to make my tests thread safe. I am testng.xml to run by providing parallel="methods" thread-count="5"

0

There are 0 best solutions below