Skip to content

Commit

Permalink
Added: JENKINS-20438 - Make it an option to show failed builds in tre…
Browse files Browse the repository at this point in the history
…nd graph
  • Loading branch information
nullin committed Feb 9, 2014
1 parent 5b93373 commit f984cfa
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 41 deletions.
1 change: 1 addition & 0 deletions README
Expand Up @@ -20,6 +20,7 @@ Release Notes
* Fixed: JENKINS-19353 - Exception error message newlines are escaped
* Fixed: JENKINS-20968 - Doesn't resolve parameters in "TestNG XML report pattern" field
* Moved some configuration into Advanced section and cleaned up help sections
* Added: JENKINS-20438 - Make it an option to show failed builds in trend graph

### v1.5
* Fixed: JENKINS-19157 - Make st:bind work when Jenkins has jQuery plugin installed
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/hudson/plugins/testng/Publisher.java
Expand Up @@ -37,17 +37,20 @@ public class Publisher extends Recorder {
public final boolean escapeTestDescp;
//should exception messages be HTML escaped or not
public final boolean escapeExceptionMsg;
//should failed builds be included in graphs or not
public final boolean showFailedBuilds;

@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

@DataBoundConstructor
public Publisher(String reportFilenamePattern,
boolean escapeTestDescp, boolean escapeExceptionMsg) {
public Publisher(String reportFilenamePattern, boolean escapeTestDescp,
boolean escapeExceptionMsg, boolean showFailedBuilds) {
reportFilenamePattern.getClass();
this.reportFilenamePattern = reportFilenamePattern;
this.escapeTestDescp = escapeTestDescp;
this.escapeExceptionMsg = escapeExceptionMsg;
this.showFailedBuilds = showFailedBuilds;
}

public BuildStepMonitor getRequiredMonitorService() {
Expand All @@ -68,7 +71,7 @@ public BuildStepDescriptor<hudson.tasks.Publisher> getDescriptor() {
@Override
public Collection<? extends Action> getProjectActions(AbstractProject<?, ?> project) {
Collection<Action> actions = new ArrayList<Action>();
actions.add(new TestNGProjectAction(project, escapeTestDescp, escapeExceptionMsg));
actions.add(new TestNGProjectAction(project, escapeTestDescp, escapeExceptionMsg, showFailedBuilds));
return actions;
}

Expand Down
17 changes: 12 additions & 5 deletions src/main/java/hudson/plugins/testng/TestNGProjectAction.java
Expand Up @@ -24,8 +24,9 @@
*/
public class TestNGProjectAction extends TestResultProjectAction implements ProminentProjectAction {

private boolean escapeTestDescp;
private boolean escapeExceptionMsg;
private transient boolean escapeTestDescp;
private transient boolean escapeExceptionMsg;
private transient boolean showFailedBuilds;

/**
* Used to figure out if we need to regenerate the graphs or not.
Expand All @@ -35,10 +36,11 @@ public class TestNGProjectAction extends TestResultProjectAction implements Prom
private transient Map<String, Integer> requestMap = new HashMap<String, Integer>();

public TestNGProjectAction(AbstractProject<?, ?> project,
boolean escapeTestDescp, boolean escapeExceptionMsg) {
boolean escapeTestDescp, boolean escapeExceptionMsg, boolean showFailedBuilds) {
super(project);
this.escapeExceptionMsg = escapeExceptionMsg;
this.escapeTestDescp = escapeTestDescp;
this.showFailedBuilds = showFailedBuilds;
}

protected Class<TestNGTestResultBuildAction> getBuildActionClass() {
Expand Down Expand Up @@ -213,8 +215,13 @@ protected void populateDataSetBuilder(DataSetBuilder<String, ChartUtil.NumberOnl
ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(build);
TestNGTestResultBuildAction action = build.getAction(getBuildActionClass());

if (build.getResult() == null || build.getResult().isWorseThan(Result.UNSTABLE)) {
//We don't want to add aborted, failed or builds with no results into the graph
if (build.getResult() == null || build.getResult().isWorseThan(Result.FAILURE)) {
//We don't want to add aborted or builds with no results into the graph
continue;
}

if (!showFailedBuilds && build.getResult().equals(Result.FAILURE)) {
//failed build and configuration states that we should skip this build
continue;
}

Expand Down
Expand Up @@ -10,5 +10,8 @@
<f:entry title="Escape exception messages?" field="escapeExceptionMsg">
<f:checkbox name="testng.escapeExceptionMsg" default="true" />
</f:entry>
<f:entry title="Show failed builds in trend graph?" field="showFailedBuilds">
<f:checkbox name="testng.showFailedBuilds" default="false" />
</f:entry>
</f:advanced>
</j:jelly>
@@ -0,0 +1,12 @@
<div>
<b>Show Failed builds in Trend Graph?</b>
<p>If checked, the plug-in includes results from failed builds in the trend graph. (Disabled by default) </p>
<p><b>Note</b>:
<ul>
<li>If this is a maven build, it is better to configure the build step with
<code>-Dmaven.test.failure.ignore=true</code> option. This results in build with test failures
being marked as Unstable, thus distinguishing it from build that failed because of non test related issues</li>
<li>Even when this option is selected, failed builds with no results and aborted builds will not be displayed in graphs</li>
</ul>
</p>
</div>
14 changes: 7 additions & 7 deletions src/test/java/hudson/plugins/testng/PublisherTest.java
@@ -1,5 +1,9 @@
package hudson.plugins.testng;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;

import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
Expand All @@ -10,10 +14,6 @@
import org.junit.Test;
import org.jvnet.hudson.test.HudsonTestCase;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -69,7 +69,7 @@ public void testLocateReports() throws Exception {

@Test
public void testBuildAborted() throws Exception {
Publisher publisher = new Publisher("**/testng-results.xml", false, false);
Publisher publisher = new Publisher("**/testng-results.xml", false, false, false);
Launcher launcherMock = mock(Launcher.class);
AbstractBuild buildMock = mock(AbstractBuild.class);
BuildListener listenerMock = mock(BuildListener.class);
Expand All @@ -89,14 +89,14 @@ public void testBuildAborted() throws Exception {
@Test
public void testRoundTrip() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher before = new Publisher("", false, false);
Publisher before = new Publisher("", false, false, true);
p.getPublishersList().add(before);

submit(createWebClient().getPage(p,"configure").getFormByName("config"));

Publisher after = p.getPublishersList().get(Publisher.class);

assertEqualBeans(before, after, "reportFilenamePattern,escapeTestDescp,escapeExceptionMsg");
assertEqualBeans(before, after, "reportFilenamePattern,escapeTestDescp,escapeExceptionMsg,showFailedBuilds");
}

}
@@ -1,5 +1,7 @@
package hudson.plugins.testng;

import java.io.IOException;

import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
Expand All @@ -11,8 +13,6 @@
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestBuilder;

import java.io.IOException;

/**
* Tests for {@link TestNGProjectAction}
*
Expand All @@ -35,7 +35,7 @@ public class TestNGProjectActionTest extends HudsonTestCase {
@Test
public void testSettings() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("some.xml", false, true);
Publisher publisher = new Publisher("some.xml", false, true, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down
Expand Up @@ -35,7 +35,7 @@ public class TestNGTestResultBuildActionTest extends HudsonTestCase {
@Test
public void testBuildAction_1() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -124,7 +124,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testBuildAction_2() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down
15 changes: 10 additions & 5 deletions src/test/java/hudson/plugins/testng/results/ClassResultTest.java
@@ -1,5 +1,13 @@
package hudson.plugins.testng.results;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Launcher;
Expand All @@ -16,9 +24,6 @@
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestBuilder;

import java.io.IOException;
import java.util.*;

/**
* Tests for {@link ClassResult}'s view page
*
Expand All @@ -43,7 +48,7 @@ public class ClassResultTest extends HudsonTestCase {
@Test
public void testPrecheckinLegacyOpsClassResults() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -143,7 +148,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testClassResults() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down
Expand Up @@ -30,7 +30,7 @@ public class MethodResultTest extends HudsonTestCase {
@Test
public void testEscapeExceptionMessageTrue() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, true /*escapeExpMsg*/);
Publisher publisher = new Publisher("testng.xml", false, true /*escapeExpMsg*/, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -58,7 +58,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testEscapeExceptionMessageFalse() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false /*escapeExpMsg*/);
Publisher publisher = new Publisher("testng.xml", false, false /*escapeExpMsg*/, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand All @@ -85,7 +85,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testEscapeDescriptionFalse() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false /*escapeDescription*/, false);
Publisher publisher = new Publisher("testng.xml", false /*escapeDescription*/, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -113,7 +113,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testEscapeDescriptionTrue() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", true /*escapeDescription*/, false);
Publisher publisher = new Publisher("testng.xml", true /*escapeDescription*/, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -149,7 +149,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testMultilineDescriptionAndExceptionMessage() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false /*escapeDescription*/, false /*escapeException*/);
Publisher publisher = new Publisher("testng.xml", false /*escapeDescription*/, false /*escapeException*/, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -179,7 +179,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testReporterLogOutput() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -213,7 +213,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testMethodResults1() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -290,7 +290,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testMethodResults_dataProviderTests() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -366,7 +366,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testMethodResults_testInstanceNames() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down
@@ -1,5 +1,10 @@
package hudson.plugins.testng.results;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Launcher;
Expand All @@ -15,11 +20,6 @@
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestBuilder;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Tests for {@link PackageResult}'s view page
*
Expand All @@ -44,7 +44,7 @@ public class PackageResultTest extends HudsonTestCase {
@Test
public void testPrecheckinPackageResults() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down Expand Up @@ -149,7 +149,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Test
public void testMyPackagePackageResults() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
Publisher publisher = new Publisher("testng.xml", false, false, false);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

Expand Down

0 comments on commit f984cfa

Please sign in to comment.