Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add passed and skipped cases to REST API response #48

Merged
merged 3 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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