Closed jrocketz closed 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.
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.
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):
And the NullPointerException:
Here are the details for my test environment:
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:I am able to query the TestRail v2 API directly without issue.