Skip to content

Commit

Permalink
Added: JENKINS-10098 - Add test/suite names to class results page
Browse files Browse the repository at this point in the history
added test/suite name values to MethodResult and now these values
are used to disambiguate different instance of the same method.
  • Loading branch information
nullin committed Jun 24, 2011
1 parent cb6d9cc commit 093b57a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Release Notes
* JENKINS-9838 - Action --> HealthReportingAction
* Fixed: JENKINS-10000 - Config methods for classes with no test methods are not displayed
* Added: JENKINS-10001 - Store/Display group names (if any) for test methods
* Added: JENKINS-10098 - Add test/suite names to class results page

### v0.24
* Fixed: JENKINS-9742 - Test Report exposes data via the Remote APIs now
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/hudson/plugins/testng/parser/ResultsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class ResultsParser {
private String currentShortStackTrace;
private String currentFullStackTrace;
private String currentGroupName;
private String currentSuite;

private enum TAGS {
TESTNG_RESULTS, SUITE, TEST, CLASS, TEST_METHOD,
Expand Down Expand Up @@ -116,6 +117,9 @@ public TestResults parse(FilePath[] paths) {
//all opening tags
case XmlPullParser.START_TAG:
switch (tag) {
case SUITE:
startSuite(get("name"));
break;
case GROUPS:
startGroups();
break;
Expand Down Expand Up @@ -252,9 +256,15 @@ private void startGroups()
methodGroupMap = new HashMap<String, List<String>>();
}

private void startSuite(String name)
{
currentSuite = name;
}

private void finishSuite()
{
methodGroupMap.clear();
currentSuite = null;
}

private void startException()
Expand Down Expand Up @@ -313,7 +323,7 @@ private void startTestMethod(String name,
String isConfig)
{
currentMethod = new MethodResult(name, status, description, duration,
startedAt, isConfig, currentTestRunId, currentTest.getName());
startedAt, isConfig, currentTestRunId, currentTest.getName(), currentSuite);
List<String> groups = methodGroupMap.get(currentClass.getName() + "|" + name);
if (groups != null) {
currentMethod.setGroups(groups);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/testng/results/ClassResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public Map<String, GroupedTestRun> getTestRunMap() {
if (this.testRunMap.containsKey(methodTestRunId)) {
group = this.testRunMap.get(methodTestRunId);
} else {
group = new GroupedTestRun();
group.setTestRunId(methodTestRunId);
group = new GroupedTestRun(methodTestRunId,
methodResult.getParentTestName(),
methodResult.getParentSuiteName());
this.testRunMap.put(methodTestRunId, group);
}

Expand Down
19 changes: 17 additions & 2 deletions src/main/java/hudson/plugins/testng/results/GroupedTestRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@ public class GroupedTestRun {

private List<MethodResult> testMethods = new ArrayList<MethodResult>();
private List<MethodResult> configurationMethods = new ArrayList<MethodResult>();
//unique id that associates methods run for a particular suite -> test -> class
private String testRunId;
//name of the associated test i.e. the <test>'s name attr
private String testName;
//name of the associate suite
private String suiteName;

public GroupedTestRun(String testRunId, String testName, String suiteName) {
this.testRunId = testRunId;
this.testName = testName;
this.suiteName = suiteName;
}

public String getTestRunId() {
return testRunId;
}

public void setTestRunId(String testRunId) {
this.testRunId = testRunId;
public String getTestName() {
return testName;
}

public String getSuiteName() {
return suiteName;
}

public List<MethodResult> getTestMethods() {
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/hudson/plugins/testng/results/MethodResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class MethodResult extends BaseResult {
private MethodResultException exception;
private Date startedAt;
private String parentTestName;
private String parentSuiteName;
private List<String> groups;
private List<String> parameters;
/**
Expand All @@ -40,14 +41,16 @@ public MethodResult(String name,
String startedAt,
String isConfig,
String testRunId,
String parentTestName)
String parentTestName,
String parentSuiteName)
{
this.name = name;
this.status = status;
this.description = description;
// this uuid is used later to group the tests and config-methods together
this.testRunId = testRunId;
this.parentTestName = parentTestName;
this.parentSuiteName = parentSuiteName;

try {
this.duration = Long.parseLong(duration);
Expand Down Expand Up @@ -82,6 +85,10 @@ public String getParentTestName() {
return parentTestName;
}

public String getParentSuiteName() {
return parentSuiteName;
}

public String getTestRunId() {
return testRunId;
}
Expand Down Expand Up @@ -191,6 +198,23 @@ public String getDisplayDuration() {
return FormatUtil.formatTimeInMilliSeconds(duration);
}

public String getDisplayGroups() {
StringBuffer sb = new StringBuffer();

if (groups != null) {
int len = groups.size();
int count = 1;
for (String grp : groups) {
sb.append(grp);
if (count++ < len) {
sb.append(", ");
}
}
}

return sb.toString();
}

public boolean isConfig() {
return isConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:forEach var="group" items="${it.testRunMap.values()}">
<h2>Test Methods</h2>
<j:if test="${group.testName != null}">
(from test '<b>${group.testName}</b>' in suite '<b>${group.suiteName}</b>')
</j:if>
<j:choose>
<j:when test="${size(group.testMethods) > 0}">
<table border="1px" class="pane sortable">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
</div>

<j:if test="${!empty(it.groups)}">
Group(s):
<j:forEach var="group" items="${it.groups}">
<ul>
<li>${group}</li>
</ul>
</j:forEach>
Group(s): ${it.displayGroups}
</j:if>

<j:if test="${!empty(it.parameters)}">
Expand Down

0 comments on commit 093b57a

Please sign in to comment.