Permalink
Browse files

Change test method uuid handling

Currently we were appending a long UUID string to test methods
to uniquely identify them. Changed this to be more like how
jenkins' junit tests work. We just append '_x' to the test method name
where x is (1,n).

Also, updated the TestResults.tally() method to *not* do weird stuff of
copying MethodResults from one ClassResult to another.
  • Loading branch information...
nullin committed Jun 7, 2011
1 parent ed4a941 commit bf1174c0d970d339b38617d1c6ced0a89b09c5a9
@@ -253,9 +253,8 @@ private void startTestMethod(String name,
String startedAt,
String isConfig)
{
- String testUuid = UUID.randomUUID().toString();
currentMethod = new MethodResult(name, status, description, duration,
- startedAt, isConfig, testUuid, currentTestRunId);
+ startedAt, isConfig, currentTestRunId);
}
private void finishTestMethod()
@@ -129,9 +129,18 @@ public void tally() {
}
}
methodResult.setParent(this);
-// if (methodInstanceMap.containsKey(methodResult.getName()) {
-//
-// }
+ /*
+ * Setup testUuids to ensure that methods with same names can be
+ * reached using unique urls
+ */
+ String methodName = methodResult.getName();
+ if (methodInstanceMap.containsKey(methodName)) {
+ int currIdx = methodInstanceMap.get(methodName);
+ methodResult.setTestUuid(String.valueOf(++currIdx));
+ methodInstanceMap.put(methodName, currIdx);
+ } else {
+ methodInstanceMap.put(methodName, 0);
+ }
}
}
@@ -142,7 +151,7 @@ public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp)
if (this.testMethodList != null) {
for (MethodResult methodResult : this.testMethodList) {
//append the uuid as well
- if (token.equals(methodResult.getName() + "--" + methodResult.getTestUuid())) {
+ if (token.equals(methodResult.getUrl())) {
return methodResult;
}
}
@@ -9,9 +9,6 @@
import java.util.Date;
import java.util.List;
-import org.kohsuke.stapler.StaplerRequest;
-import org.kohsuke.stapler.StaplerResponse;
-
@SuppressWarnings("serial")
public class MethodResult extends BaseResult {
@@ -39,14 +36,11 @@ public MethodResult(String name,
String duration,
String startedAt,
String isConfig,
- String testUuid,
String testRunId)
{
this.name = name;
this.status = status;
this.description = description;
- // TODO: Need better handling of test run and method UUIDs
- this.testUuid = testUuid;
// this uuid is used later to group the tests and config-methods together
this.testRunId = testRunId;
@@ -75,6 +69,10 @@ public String getTestUuid() {
return testUuid;
}
+ public void setTestUuid(String testUuid) {
+ this.testUuid = testUuid;
+ }
+
public String getTestRunId() {
return testRunId;
}
@@ -98,7 +96,11 @@ public void setException(MethodResultException exception) {
}
public String getUrl() {
- return getName() + "--" + this.testUuid;
+ String url = getName();
+ if (this.testUuid != null) {
+ url += "_" + this.testUuid;
+ }
+ return url;
}
public long getDuration() {
@@ -143,13 +145,6 @@ public boolean isConfig() {
return isConfig;
}
- public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) {
- if (token.equals("/" + getName() + "--" + this.testUuid)) {
- return this;
- }
- return null;
- }
-
/**
* Create a list that contains previous builds results for this method
* <p/>
@@ -168,34 +168,8 @@ public void tally() {
}
if (packageMap.containsKey(pkg)) {
List<ClassResult> classResults = packageMap.get(pkg).getClassList();
- boolean classAlreadyAddedToPackage = false;
- for (ClassResult classResult : classResults) {
- if (classResult.getName().equals(_class.getName())) {
- //let's merge the testMethods
- //loop through and don't add them if the name, startTime, endTime and
- //other fields are identical
- List<MethodResult> methods = classResult.getTestMethodList();
- List<MethodResult> _methods = _class.getTestMethodList();
- for (MethodResult _method : _methods) {
- boolean _methodAlreadyAdded = false;
- for (MethodResult method : methods) {
- if(_method.getName().equals(method.getName()) &&
- _method.getDuration() == method.getDuration() &&
- _method.getStartedAt().equals(method.getStartedAt())) {
- _methodAlreadyAdded = true;
- break;
- }
- }
- if(!_methodAlreadyAdded) {
- classResult.addTestMethod(_method);
- }
- }
- classAlreadyAddedToPackage = true;
- break;
- }
- }
- if (!classAlreadyAddedToPackage) {
- packageMap.get(pkg).getClassList().add(_class);
+ if (!classResults.contains(_class)) {
+ classResults.add(_class);
}
} else {
PackageResult tpkg = new PackageResult(pkg);

0 comments on commit bf1174c

Please sign in to comment.