mardi 28 mars 2017

Rest-Assured. Random "Cannot invoke method getAt() on null object" Error when running multiple test suites in Maven

I have a couple of test suites using Rest-Assured, JUnitParams, and JUnit4, this suites share a @Test method that has this portion of code, the code randomly gets an item from the JSON response that has a "children_uuids" value in them:

            // Test case
            response = serviceCaller.call();

            Boolean success = response.then().extract().path("Success");
            assertTrue(success);

            // get random content data
            Integer contentAmmount = response.body().path("Contents.Contents.size()");
            Random randomGenerator = new Random();
            int randomInt = randomGenerator.nextInt(contentAmmount);
            while (response.body().path(
                    String.join("", "Contents.Contents[", Integer.toString(randomInt), "].children_uuids"))
                    .toString().isEmpty()) {
                randomInt = randomGenerator.nextInt(contentAmmount);
            }

            contentTitle = response.then().extract()
                    .path(String.join("", "Contents.Contents[", Integer.toString(randomInt), "].title"));
            contentUuid = response.then().extract()
                    .path(String.join("", "Contents.Contents[", Integer.toString(randomInt), "].uuid"));
            contentChildrenUuid = response.body().path(
                    String.join("", "Contents.Contents[", Integer.toString(randomInt), "].children_uuids.item[0]"));
            System.out.println(contentTitle + "#" + contentChildrenUuid);

The problem is, that if i run only one test suite with the command:

mvn test -Dtest=TestSuite01#testCase01

The test runs fine, but if i run all the suites with the command:

mvn test -Dtest=TestSuite*#testCase01

I get the following error randomly in some suites:

java.lang.IllegalArgumentException: Cannot invoke method getAt() on null object
Results :

Tests in error: 
  TestSuite01>ApiServiceCommon.testCase01:1023 » IllegalArgument

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire