Skip to content
Permalink
Browse files

JENKINS-11413: Add maximum size limit to ${FAILED_TESTS}

Add a maxTests argument to the ${FAILED_TESTS} token.

The setting is undefined by default for backwards compatibility with existing configurations.
  • Loading branch information...
jukka committed Nov 23, 2011
1 parent dc7025b commit 580607952350daf008360071fc21c3235483a8ad
@@ -21,16 +21,23 @@

private static final String TOKEN = "FAILED_TESTS";

public static final String MAX_TESTS_ARG_NAME = "maxTests";

public String getToken() {
return TOKEN;
}

public List<String> getArguments() {
return Collections.emptyList();
return Collections.singletonList(MAX_TESTS_ARG_NAME);
}

public String getHelpText() {
return "Displays failing unit test information, if any tests have failed.";
return "Displays failing unit test information, if any tests have failed.\n"
+ "<ul>\n"
+ "<li><i>" + MAX_TESTS_ARG_NAME + "</i> - display at most this many failing tests.<br>\n"
+ "No limit is set by default.\n"
+ "</ul>\n";

}

public <P extends AbstractProject<P, B>, B extends AbstractBuild<P, B>> String getContent(AbstractBuild<P, B> build, ExtendedEmailPublisher publisher,
@@ -52,9 +59,20 @@ public String getHelpText() {
buffer.append(" tests failed.");
buffer.append('\n');

List<CaseResult> failedTests = testResult.getFailedTests();
for (CaseResult failedTest : failedTests) {
outputTest(buffer, failedTest);
int maxTests = Args.get(args, MAX_TESTS_ARG_NAME, Integer.MAX_VALUE);
if (maxTests > 0) {
int printedTests = 0;
for (CaseResult failedTest : testResult.getFailedTests()) {
if (printedTests < maxTests) {
outputTest(buffer, failedTest);
printedTests++;
}
}
if (failCount > printedTests) {
buffer.append("... and ");
buffer.append(failCount - printedTests);
buffer.append(" other failed tests.\n\n");
}
}
}

@@ -1,5 +1,8 @@
package hudson.plugins.emailext.plugins.content;

import java.util.Collections;
import java.util.Map;

import hudson.model.AbstractBuild;
import hudson.tasks.test.AbstractTestResultAction;
import org.junit.Before;
@@ -43,4 +46,20 @@ public void testGetContent_whenAllTestsPassedShouldGiveMeaningfulMessage()

assertEquals( "All tests passed", content );
}

@Test
public void testGetContent_whenSomeTestsFailedShouldGiveMeaningfulMessage()
{
AbstractTestResultAction<?> testResults = mock( AbstractTestResultAction.class );
when( testResults.getFailCount() ).thenReturn( 123 );

when( build.getTestResultAction() ).thenReturn( testResults );

Map<String, Integer> args = Collections.singletonMap(
FailedTestsContent.MAX_TESTS_ARG_NAME, 0 );
String content = failedTestContent.getContent( build, null, null, args );

assertEquals( "123 tests failed.\n", content );
}

}

0 comments on commit 5806079

Please sign in to comment.
You can’t perform that action at this time.