RetailMeNot / TestRailSDK

TestRail integration with Java WebDriver implementation.
MIT License
25 stars 27 forks source link

NullPointerException occurs when getting List<TestInstance> from a TestRun #15

Closed jrocketz closed 9 years ago

jrocketz commented 9 years ago

I tried to get a list of TestInstances from a TestRun, and was greeted with a NullPointerException. Here is the code that you can use to test (Note: I removed my hard-coded entries for my account and project information):

import java.util.List;
import com.rmn.testrail.entity.Project;
import com.rmn.testrail.entity.TestInstance;
import com.rmn.testrail.entity.TestPlan;
import com.rmn.testrail.entity.TestRun;
import com.rmn.testrail.entity.TestRunGroup;
import com.rmn.testrail.service.TestRailService;

public class TestRailSDK {

    public static void main(String[] args) {

        TestRailService testRailService = new TestRailService(clientId, username, password);
        Project project = testRailService.getProjectByName(projectName);
        TestPlan testPlan = project.getTestPlanByName(testPlanName);
        List<TestRunGroup> testRunGroups = testPlan.getEntries();
        for (TestRunGroup testRunGroup: testRunGroups) {
            List<TestRun> testRuns = testRunGroup.getRuns();
            for (TestRun testRun: testRuns) {
                List<TestInstance> testInstances = testRun.getTests();
            }
        }
    }

}

And the NullPointerException:

Exception in thread "main" java.lang.NullPointerException
    at com.rmn.testrail.entity.TestRun.getTests(TestRun.java:122)
    at com.transverse.tract.TestRailSDK.main(TestRailSDK.java:22

Here are the details for my test environment:

TestRail v4.1.0.3294 (Hosted)
TestRailSDK 0.9

Within my test plan, I have the following test groups and runs:

Test Run Group 1

Test Run Group 2

This appears to be the offending code in TestRun.java although I can't determine why it failed:

/**
* @return the list of TestInstance entities associated with this TestRun
*/
public List<TestInstance> getTests() {
return getTestRailService().getTests( this.getId() );
}

I am able to query the TestRail v2 API directly without issue.

jrocketz commented 9 years ago

Here's an update. I am able to get the Test Instances from a single Test Run that is specified by the Test Run ID. Here is the code that I used:

import java.util.List;
import com.rmn.testrail.entity.Project;
import com.rmn.testrail.entity.TestInstance;
import com.rmn.testrail.entity.TestPlan;
import com.rmn.testrail.entity.TestRun;
import com.rmn.testrail.entity.TestRunGroup;
import com.rmn.testrail.service.TestRailService;

public class TestRailSDK {

    public static void main(String[] args) {

        TestRailService testRailService = new TestRailService(clientId, username, password);
        Project project = testRailService.getProjectByName(projectName);
        TestPlan testPlan = project.getTestPlanByName(testPlanName);
        List<TestRunGroup> testRunGroups = testPlan.getEntries();
        List<TestInstance> testInstances = testRailService.getTestRun(149).getTests();
        for (TestInstance testInstance: testInstances) {
            System.out.println("Test Run: " + testRailService.getTestRun(149).getName());
            System.out.println("Case ID: " + testInstance.getCaseId());
            System.out.println("Test ID: " + testInstance.getId());
        }
    }

}

And here is the output:

Test Run: Test Run Group 1
Case ID: 5517
Test ID: 103431
Test Run: Test Run Group 1
Case ID: 5518
Test ID: 103432

The problem seems to occur when getting the Test Instances while iterating through the Test Runs.

jrocketz commented 9 years ago

This issue can be closed. I neglected to query the TestRail service when getting the test instances. Updating this section of code:

for (TestRun testRun: testRuns) {
   List<TestInstance> testInstances = testRun.getTests();
}

To this:

for (TestRun testRun: testRuns) {
   List<TestInstance> testInstances = testRailService.getTestRun(testRun.getId()).getTests();
}

resolved the problem.