Skip to content

Commit

Permalink
Fixed JENKINS-9918 and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
nullin committed Sep 21, 2011
1 parent 9080487 commit 0309746
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 36 deletions.
10 changes: 7 additions & 3 deletions README
Expand Up @@ -16,12 +16,16 @@ graph and all details about which tests that failed are also presented.
Release Notes
-------

### upcoming
### Future Releases
* JENKINS-9838 - Action --> HealthReportingAction
* JENKINS-10018 - New graph for test method details page

### v0.28
* Bumped up supported Jenkins version to v1.403 or later
* Fixed: JENKINS-9918 - Limit the number of rows in method execution order table

### v0.27
* JENKINS-10882 - Add duration in the XML API for test-result, package and classes [Nicolas De Loof]
* Added: JENKINS-10882 - Add duration in the XML API for test-result, package and classes [Nicolas De Loof]
* Added: JENKINS-10018 - New graph for test method details page

### v0.26
* Added: JENKINS-8926 - Add group name to class test methods page
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.399</version>
<version>1.403</version>
</parent>

<artifactId>testng-plugin</artifactId>
Expand Down
88 changes: 79 additions & 9 deletions src/main/java/hudson/plugins/testng/results/PackageResult.java
@@ -1,6 +1,7 @@
package hudson.plugins.testng.results;

import hudson.model.AbstractBuild;
import hudson.plugins.testng.util.FormatUtil;
import hudson.plugins.testng.util.TestResultHistoryUtil;

import java.util.ArrayList;
Expand All @@ -13,6 +14,7 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.bind.JavaScriptMethod;

@SuppressWarnings("serial")
public class PackageResult extends BaseResult {
Expand All @@ -25,6 +27,8 @@ public class PackageResult extends BaseResult {
private transient int skip;
private transient int total;

public final int MAX_EXEC_MTHD_LIST_SIZE = 25;

public PackageResult(String name) {
super(name);
}
Expand Down Expand Up @@ -61,6 +65,12 @@ public int getTotal() {
return total;
}

/**
* Gets the age of a result
*
* @return the number of consecutive builds for which we have a result for
* this package
*/
public long getAge() {
PackageResult packageResult = getPreviousPackageResult();
if (packageResult == null) {
Expand All @@ -70,13 +80,69 @@ public long getAge() {
}
}

/**
* Gets all the method results related to this package sorted by the time
* the methods were executed
*
* @return
*/
public List<MethodResult> getSortedTestMethodsByStartTime() {
if (sortedTestMethodsByStartTime == null) {
sortTestMethods();
}
return sortedTestMethodsByStartTime;
}

/**
* Gets table row representation for all the method results associated with
* this package (sorted based on start time)
* @return
*/
@JavaScriptMethod
public String getAllSortedTestMethodsByStartTime() {
return getMethodExecutionTableContent(getSortedTestMethodsByStartTime());
}

/**
* Gets table row representation for the first {@link #MAX_EXEC_MTHD_LIST_SIZE}
* method results associated with this package (sorted based on start time)
*
* @return
*/
@JavaScriptMethod
public String getFirstXSortedTestMethodsByStartTime() {
//returning the first MAX results only
List<MethodResult> list = getSortedTestMethodsByStartTime();
list = list.subList(0, list.size() > MAX_EXEC_MTHD_LIST_SIZE
? MAX_EXEC_MTHD_LIST_SIZE : list.size());
return getMethodExecutionTableContent(list);
}

/**
* Gets the table row representation for the specified method results
*
* @param mrList list of method result objects
* @return table row representation
*/
private String getMethodExecutionTableContent(List<MethodResult> mrList) {
StringBuffer sb = new StringBuffer(mrList.size() * 100);

for (MethodResult mr : mrList) {
sb.append("<tr><td align=\"left\">");
sb.append("<a href=\"../").append(mr.getFullUrl()).append("\">");
sb.append(mr.getParent().getName()).append(".").append(mr.getName());
sb.append("</a>");
sb.append("</td><td align=\"center\">");
sb.append(FormatUtil.formatTimeInMilliSeconds(mr.getDuration()));
sb.append("</td><td align=\"center\">");
sb.append(mr.getStartedAt());
sb.append("</td><td align=\"center\"><span class=\"").append(mr.getCssClass()).append("\">");
sb.append(mr.getStatus());
sb.append("</span></td></tr>");
}
return sb.toString();
}

public void tally() {
duration = 0;
fail = 0;
Expand Down Expand Up @@ -107,22 +173,26 @@ public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp)
return result;
}

/**
* Sorts the test method results associated with this package based on the
* start time for method execution
*/
public void sortTestMethods() {
this.sortedTestMethodsByStartTime = new ArrayList<MethodResult>();
//for each class
Map<Date, List<MethodResult>> map = new HashMap<Date, List<MethodResult>>();
for (ClassResult aClass : classList) {
if (aClass.getTestMethods() != null) {
for (MethodResult aMethod : aClass.getTestMethods()) {
if (!aMethod.getStatus().equalsIgnoreCase("skip")) {
if (aMethod.getStartedAt() != null) {
if (map.containsKey(aMethod.getStartedAt())) {
map.get(aMethod.getStartedAt()).add(aMethod);
} else {
List<MethodResult> list = new ArrayList<MethodResult>();
list.add(aMethod);
map.put(aMethod.getStartedAt(), list);
}
Date startDate = aMethod.getStartedAt();
if (!aMethod.getStatus().equalsIgnoreCase("skip")
&& startDate != null) {
if (map.containsKey(startDate)) {
map.get(startDate).add(aMethod);
} else {
List<MethodResult> list = new ArrayList<MethodResult>();
list.add(aMethod);
map.put(startDate, list);
}
}
}
Expand Down
Expand Up @@ -9,6 +9,16 @@
document.getElementById(id).style.display = "none";
}
}
//Loads data for all the methods
function showAllExecutedMethods() {
var foo = <st:bind value="${it}"/>

foo.getAllSortedTestMethodsByStartTime(function(t) {
document.getElementById('sortedMethods').innerHTML = t.responseObject();
})

document.getElementById("showAllLink").style.display = "none";
}
</script>
<h2>All Classes</h2>
<a href="javascript:showorHideTable('allClasses')">hide/expand the table</a>
Expand Down Expand Up @@ -75,6 +85,12 @@
<div>No Tests found or all Tests were skipped</div>
</j:when>
<j:otherwise>
<j:if test="${size(it.sortedTestMethodsByStartTime) > it.MAX_EXEC_MTHD_LIST_SIZE}">
<div id="showAllLink">
<p>Showing only first ${it.MAX_EXEC_MTHD_LIST_SIZE} test methods.
<a href="javascript:showAllExecutedMethods()">Click to see all</a></p>
</div>
</j:if>
<a href="javascript:showorHideTable('executionOrderTable')">hide/expand the table</a>
<table border="1px" class="pane sortable" id="executionOrderTable">
<thead>
Expand All @@ -85,31 +101,18 @@
<th class="pane-header" style="width:5em" title="Status">Fail</th>
</tr>
</thead>
<tbody>
<j:forEach var="method" items="${it.sortedTestMethodsByStartTime}">
<j:choose>
<tr>
<td align="left">
<a href="../${method.fullUrl}">${method.parent.name}.${method.name}</a>
</td>
<td align="center" data="${method.duration}">
<j:invokeStatic className="hudson.plugins.testng.util.FormatUtil"
method="formatTimeInMilliSeconds" var="duration">
<j:arg type="long" value="${method.duration}"/>
</j:invokeStatic>
${duration}
</td>
<td align="center">${method.startedAt}</td>
<td align="center">
<span class="${method.cssClass}">
${method.status}
</span>
</td>
</tr>
</j:choose>
</j:forEach>
<tbody id="sortedMethods">
<!-- updated using ajax -->
</tbody>
</table>
<!-- following script loads the initial table data -->
<script>
var foo = <st:bind value="${it}"/>

foo.getFirstXSortedTestMethodsByStartTime(function(t) {
document.getElementById('sortedMethods').innerHTML = t.responseObject();
})
</script>
</j:otherwise>
</j:choose>
</j:jelly>

0 comments on commit 0309746

Please sign in to comment.