Skip to content

Commit

Permalink
Add passed and skipped cases to REST API response (#48)
Browse files Browse the repository at this point in the history
* Add passed and skipped cases to REST API response

* Add docstring to functions
  • Loading branch information
asimell authored May 27, 2022
1 parent 0f765d7 commit b2f43bf
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 9 deletions.
79 changes: 72 additions & 7 deletions src/main/java/hudson/plugins/robot/model/RobotResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,87 @@ public List<RobotCaseResult> getAllFailedCases(){
Collections.sort(allFailedCases, new RobotCaseComparator());
return allFailedCases;
}


/**
* Get all passed test cases related to result.
* @return list of test case results
*/
public List<RobotCaseResult> getAllPassedCases(){
List<RobotCaseResult> allPassedCases = new ArrayList<>();
for(RobotSuiteResult suite : getSuites()){
List<RobotCaseResult> passedCases = suite.getAllPassedCases();
allPassedCases.addAll(passedCases);
}
Collections.sort(allPassedCases, new RobotCaseComparator());
return allPassedCases;
}

/**
* Get all skipped test cases related to result.
* @return list of test case results
*/
public List<RobotCaseResult> getAllSkippedCases(){
List<RobotCaseResult> allSkippedCases = new ArrayList<>();
for(RobotSuiteResult suite : getSuites()){
List<RobotCaseResult> skippedCases = suite.getAllSkippedCases();
allSkippedCases.addAll(skippedCases);
}
Collections.sort(allSkippedCases, new RobotCaseComparator());
return allSkippedCases;
}

/**
* Get all failed test case names related to result.
* @return list of test case names as strings
*/
@Exported
public List<String> getFailedCases() {
List<String> failedCases = new ArrayList<>();
for (RobotCaseResult robotCaseResult : this.getAllFailedCases()) {
RobotTestObject rto = robotCaseResult.getParent();
String name = robotCaseResult.getName();
while (rto != null && !rto.getName().isEmpty()) {
name = rto.getName()+"."+name;
rto = rto.getParent();
}
String name = this.getCaseName(robotCaseResult);
failedCases.add(name);
}
return failedCases;
}

/**
* Get all passed test case names related to result.
* @return list of test case names as strings
*/
@Exported
public List<String> getPassedCases() {
List<String> passedCases = new ArrayList<>();
for (RobotCaseResult robotCaseResult : this.getAllPassedCases()) {
String name = this.getCaseName(robotCaseResult);
passedCases.add(name);
}
return passedCases;
}

/**
* Get all skipped test case names related to result.
* @return list of test case names as strings
*/
@Exported
public List<String> getSkippedCases() {
List<String> skippedCases = new ArrayList<>();
for (RobotCaseResult robotCaseResult : this.getAllSkippedCases()) {
String name = this.getCaseName(robotCaseResult);
skippedCases.add(name);
}
return skippedCases;
}

private String getCaseName(RobotCaseResult robotCaseResult) {
RobotTestObject rto = robotCaseResult.getParent();
String name = robotCaseResult.getName();
while (rto != null && !rto.getName().isEmpty()) {
name = rto.getName()+"."+name;
rto = rto.getParent();
}
return name;
}

/**
* Count the totals in result tree and assign parent action.
* @param robotBuildAction The action to be used as the base
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/hudson/plugins/robot/model/RobotSuiteResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,48 @@ public List<RobotSuiteResult> getAllChildSuites() {
*/
public List<RobotCaseResult> getAllFailedCases() {
List<RobotCaseResult> failedCases = new ArrayList<>();
for(RobotCaseResult caseResult : getCaseResults()){
for(RobotCaseResult caseResult : getCaseResults()) {
if(!caseResult.isPassed() && !caseResult.isSkipped()) failedCases.add(caseResult);
}
for(RobotSuiteResult suite : getChildSuites()){
for(RobotSuiteResult suite : getChildSuites()) {
failedCases.addAll(suite.getAllFailedCases());
}
Collections.sort(failedCases, new RobotCaseComparator());
return failedCases;
}

/**
* Get all passed cases in this suite and its child suites
* @return all passed cases in this suite and its child suites
*/
public List<RobotCaseResult> getAllPassedCases() {
List<RobotCaseResult> passedCases = new ArrayList<>();
for(RobotCaseResult caseResult : getCaseResults()) {
if(caseResult.isPassed()) passedCases.add(caseResult);
}
for(RobotSuiteResult suite : getChildSuites()) {
passedCases.addAll(suite.getAllPassedCases());
}
Collections.sort(passedCases, new RobotCaseComparator());
return passedCases;
}

/**
* Get all skipped cases in this suite and its child suites
* @return all skipped cases in this suite and its child suites
*/
public List<RobotCaseResult> getAllSkippedCases() {
List<RobotCaseResult> skippedCases = new ArrayList<>();
for(RobotCaseResult caseResult : getCaseResults()) {
if(caseResult.isSkipped()) skippedCases.add(caseResult);
}
for(RobotSuiteResult suite : getChildSuites()) {
skippedCases.addAll(suite.getAllSkippedCases());
}
Collections.sort(skippedCases, new RobotCaseComparator());
return skippedCases;
}

/**
* Get all cases in this suite and its child suites
* @return all cases in this suite and its child suites
Expand Down

0 comments on commit b2f43bf

Please sign in to comment.