Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-2166] Use ChoiceFormat to selective render percentage and elapsed time in SurefireReportRenderer #639

Merged
merged 1 commit into from May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,7 +19,6 @@
package org.apache.maven.plugins.surefire.report;

import java.io.File;
import java.text.NumberFormat;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -100,6 +99,16 @@ private String getI18nString(String section, String key) {
return i18n.getString("surefire-report", locale, "report." + section + '.' + key);
}

/**
* @param section The section.
* @param key The key to translate.
* @param args The args to pass to translated string.
* @return the translated key.
*/
private String formatI18nString(String section, String key, Object... args) {
return i18n.format("surefire-report", locale, "report." + section + '.' + key, args);
}

public void renderBody() {
javaScript(javascriptToggleDisplayCode());

Expand All @@ -120,9 +129,6 @@ public void renderBody() {

private void renderSectionSummary() {
Map<String, Object> summary = parser.getSummary(testSuites);
NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
NumberFormat percentFormat = NumberFormat.getPercentInstance(locale);
percentFormat.setMinimumFractionDigits(1);

sink.section1();
sinkAnchor("Summary");
Expand Down Expand Up @@ -150,8 +156,8 @@ private void renderSectionSummary() {
String.valueOf(summary.get("totalErrors")),
String.valueOf(summary.get("totalFailures")),
String.valueOf(summary.get("totalSkipped")),
percentFormat.format(summary.get("totalPercentage")),
numberFormat.format(summary.get("totalElapsedTime")) + " s"
formatI18nString("surefire", "value.successrate", summary.get("totalPercentage")),
formatI18nString("surefire", "value.time", summary.get("totalElapsedTime"))
});

endTable();
Expand All @@ -171,10 +177,6 @@ private void renderSectionPackages() {
return;
}

NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
NumberFormat percentFormat = NumberFormat.getPercentInstance(locale);
percentFormat.setMinimumFractionDigits(1);

sink.section1();
sinkAnchor("Package_List");
sink.sectionTitle1();
Expand Down Expand Up @@ -210,8 +212,8 @@ private void renderSectionPackages() {
String.valueOf(packageSummary.get("totalErrors")),
String.valueOf(packageSummary.get("totalFailures")),
String.valueOf(packageSummary.get("totalSkipped")),
percentFormat.format(packageSummary.get("totalPercentage")),
numberFormat.format(packageSummary.get("totalElapsedTime")) + " s"
formatI18nString("surefire", "value.successrate", packageSummary.get("totalPercentage")),
formatI18nString("surefire", "value.time", packageSummary.get("totalElapsedTime"))
});
}

Expand Down Expand Up @@ -273,10 +275,6 @@ private void renderSectionPackages() {
}

private void renderSectionTestSuite(ReportTestSuite suite) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
NumberFormat percentFormat = NumberFormat.getPercentInstance(locale);
percentFormat.setMinimumFractionDigits(1);

sink.tableRow();

sink.tableCell();
Expand Down Expand Up @@ -310,9 +308,9 @@ private void renderSectionTestSuite(ReportTestSuite suite) {
float percentage = parser.computePercentage(
suite.getNumberOfTests(), suite.getNumberOfErrors(),
suite.getNumberOfFailures(), suite.getNumberOfSkipped());
tableCell(percentFormat.format(percentage));
tableCell(formatI18nString("surefire", "value.successrate", percentage));

tableCell(numberFormat.format(suite.getTimeElapsed()) + " s");
tableCell(formatI18nString("surefire", "value.time", suite.getTimeElapsed()));

sink.tableRow_();
}
Expand Down Expand Up @@ -372,8 +370,6 @@ private void renderSectionTestCases() {
}

private void constructTestCaseSection(ReportTestCase testCase) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);

sink.tableRow();

sink.tableCell();
Expand Down Expand Up @@ -427,7 +423,7 @@ private void constructTestCaseSection(ReportTestCase testCase) {
sinkCellAnchor(testCase.getName(), "TC_" + toHtmlId(testCase.getFullName()));
}

tableCell(numberFormat.format(testCase.getTime()) + " s");
tableCell(formatI18nString("surefire", "value.time", testCase.getTime()));

sink.tableRow_();

Expand Down
Expand Up @@ -35,6 +35,12 @@ report.surefire.label.testcases=Test Cases
report.surefire.label.failuredetails=Failure Details
report.surefire.text.note1=Note: failures are anticipated and checked for with assertions while errors are unanticipated.
report.surefire.text.note2=Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers.
report.surefire.value.successrate={0,choice,0#0%|0.0<{0,number,0.0%}|1#{0,number,0%}}
# Rationale: The idea is to always display four digits for visually consistent output
# Important:
# * Keep in sync with org.apache.maven.plugin.surefire.report.WrappedReportEntry
# * Needs to be copied into other bundles only if non-Latin script is used
report.surefire.value.time={0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s

report.failsafe.name=Failsafe
report.failsafe.description=Report on the integration test results of the project.
Expand Down
Expand Up @@ -35,6 +35,7 @@ report.surefire.label.tests=Tests
report.surefire.label.time =Zeit
report.surefire.text.note1 =Hinweis: Fehlschl\u00E4ge werden erwartet und durch Behauptungen \u00FCberpr\u00FCft w\u00E4hrend Fehler unerwartet sind.
report.surefire.text.note2 =Hinweis: Die Paketstatistiken werden nicht rekursiv berechnet, es werden lediglich die Ergebnisse aller enthaltenen Tests aufsummiert.
report.surefire.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}}

report.failsafe.name=Failsafe
report.failsafe.description=Bericht \u00FCber die Integrationstestresultate des Projekts.
Expand Down
Expand Up @@ -35,6 +35,7 @@ report.surefire.label.testcases=Testfall
report.surefire.label.failuredetails=Detaljer om misslyckade tester
report.surefire.text.note1=Notera: misslyckade tester \u00e4r f\u00f6rv\u00e4ntade och har kontrollerats med assertions medan felaktiga tester \u00e4r ov\u00e4ntade.
report.surefire.text.note2=Notera: paketstatistiken ber\u00e4knas inte rekursivt, den summerar bara alla testsviters antal.
report.surefire.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}}

report.failsafe.name=Failsafe
report.failsafe.description=Rapport om integration testresultaten f\u00f6r projektet.
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void testCorruptedTestCaseFailureWithMissingErrorTypeAndMessage() throws
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td>"
+ "</tr>"
+ "</table>")));
Expand All @@ -87,7 +87,7 @@ public void testCorruptedTestCaseFailureWithMissingErrorTypeAndMessage() throws
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr></table>")));
assertThat(
xml,
Expand All @@ -108,7 +108,7 @@ public void testCorruptedTestCaseFailureWithMissingErrorTypeAndMessage() throws
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr></table>")));
assertThat(
xml,
Expand Down
Expand Up @@ -193,7 +193,7 @@ public void testSurefireReportSingleError() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td>")));

assertThat(
Expand All @@ -204,7 +204,7 @@ public void testSurefireReportSingleError() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));
assertThat(
htmlContent,
Expand All @@ -219,7 +219,7 @@ public void testSurefireReportSingleError() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));

assertThat(htmlContent, containsString(">surefire.MyTest:13</a>"));
Expand Down Expand Up @@ -281,7 +281,7 @@ public void testSurefireReportNestedClassTrimStackTrace() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td>")));

assertThat(
Expand All @@ -292,7 +292,7 @@ public void testSurefireReportNestedClassTrimStackTrace() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));
assertThat(
htmlContent,
Expand All @@ -307,7 +307,7 @@ public void testSurefireReportNestedClassTrimStackTrace() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));
assertThat(htmlContent, containsString(">surefire.MyTest:13</a>"));

Expand Down Expand Up @@ -344,7 +344,7 @@ public void testSurefireReportNestedClass() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td>")));

assertThat(
Expand All @@ -355,7 +355,7 @@ public void testSurefireReportNestedClass() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));
assertThat(
htmlContent,
Expand All @@ -370,7 +370,7 @@ public void testSurefireReportNestedClass() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));
assertThat(htmlContent, containsString(">surefire.MyTest:13</a>"));

Expand Down Expand Up @@ -432,7 +432,7 @@ public void testSurefireReportEnclosedTrimStackTrace() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td>")));

assertThat(
Expand All @@ -443,7 +443,7 @@ public void testSurefireReportEnclosedTrimStackTrace() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));
assertThat(
htmlContent,
Expand All @@ -458,7 +458,7 @@ public void testSurefireReportEnclosedTrimStackTrace() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));

assertThat(htmlContent, containsString(">surefire.MyTest$A:45</a>"));
Expand Down Expand Up @@ -495,7 +495,7 @@ public void testSurefireReportEnclosed() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td>")));

assertThat(
Expand All @@ -506,7 +506,7 @@ public void testSurefireReportEnclosed() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));
assertThat(
htmlContent,
Expand All @@ -521,7 +521,7 @@ public void testSurefireReportEnclosed() throws Exception {
+ "<td>1</td>\n"
+ "<td>0</td>\n"
+ "<td>0</td>\n"
+ "<td>0.0%</td>\n"
+ "<td>0%</td>\n"
+ "<td>0 s</td></tr>")));

assertThat(htmlContent, containsString(">surefire.MyTest$A:45</a>"));
Expand Down