Skip to content

Commit

Permalink
[FIXED JENKINS-16647] Added column for duration ms in test results UI
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Feb 26, 2013
1 parent e3c3aa3 commit 79e5e61
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/tap4j/plugin/model/TapTestResultResult.java
Expand Up @@ -30,6 +30,7 @@
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.tap4j.model.Comment;
Expand All @@ -46,6 +47,8 @@
*/
public class TapTestResultResult extends TestResult {

private static final String DURATION_KEY = "duration_ms";

private static final long serialVersionUID = -4499261655602135921L;
private final AbstractBuild<?, ?> owner;
private final org.tap4j.model.TestResult tapTestResult;
Expand Down Expand Up @@ -175,6 +178,19 @@ public String getTitle() {
return getName();
}

@Override
public float getDuration() {
Map<String, Object> diagnostic = this.tapTestResult.getDiagnostic();
if (diagnostic != null && ! diagnostic.isEmpty()) {
Object duration = diagnostic.get(DURATION_KEY);
if (duration != null) {
Float durationMS = Float.parseFloat(duration.toString());
return durationMS.floatValue();
}
}
return super.getDuration();
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/org/tap4j/plugin/issue16647/TestIssue16647.java
@@ -0,0 +1,59 @@
package org.tap4j.plugin.issue16647;

import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import hudson.model.AbstractBuild;
import hudson.model.FreeStyleProject;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestBuilder;
import org.tap4j.plugin.TapPublisher;
import org.tap4j.plugin.TapTestResultAction;
import org.tap4j.plugin.model.TapStreamResult;
import org.tap4j.plugin.model.TapTestResultResult;

public class TestIssue16647 extends HudsonTestCase {

public void testDurationMs() throws IOException, InterruptedException, ExecutionException {
FreeStyleProject project = this.hudson.createProject(FreeStyleProject.class, "tap-bug-16647");

final String tap = "1..2\n" +
"ok 1 - Input file opened\n" +
"not ok 2 - First line of the input valid\n" +
" ---\n" +
" duration_ms: 100.66\n" +
" ...\n";

project.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher arg1,
BuildListener arg2) throws InterruptedException, IOException {
build.getWorkspace().child("result.tap").write(tap,"UTF-8");
return true;
}
});

TapPublisher publisher = new TapPublisher(
"result.tap",
true,
true,
true,
true,
true,
true);
project.getPublishersList().add(publisher);
project.save();
FreeStyleBuild build = (FreeStyleBuild) project.scheduleBuild2(0).get();

TapTestResultAction action = build.getAction(TapTestResultAction.class);
TapStreamResult result = (TapStreamResult) action.getResult();

TapTestResultResult[] results = result.getChildren().toArray(new TapTestResultResult[0]);
assertEquals(100.66f, results[1].getDuration());
}

}
4 changes: 4 additions & 0 deletions src/test/java/org/tap4j/plugin/issue16647/package-info.java
@@ -0,0 +1,4 @@
/**
* Tests for issue JENKINS-16647.
*/
package org.tap4j.plugin.issue16647;

0 comments on commit 79e5e61

Please sign in to comment.