Skip to content

Commit

Permalink
Merge f55e807 into e7597ac
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner authored Mar 10, 2024
2 parents e7597ac + f55e807 commit 12fb07c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 47 deletions.
16 changes: 8 additions & 8 deletions src/main/java/edu/hm/hafner/grading/AnalysisMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected void createSpecificDetails(final AggregatedScore aggregation, final Li

if (score.getSubScores().size() > 1) {

Check warning on line 54 in src/main/java/edu/hm/hafner/grading/AnalysisMarkdown.java

View check run for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 54 (ConditionalsBoundaryMutator)
Raw output
Survived mutations:
- changed conditional boundary (org.pitest.mutationtest.engine.gregor.mutators.ConditionalsBoundaryMutator)
details.addText(formatBoldColumns("Total",
sum(aggregation, AnalysisScore::getErrorSize),
sum(aggregation, AnalysisScore::getHighSeveritySize),
sum(aggregation, AnalysisScore::getNormalSeveritySize),
sum(aggregation, AnalysisScore::getLowSeveritySize),
sum(aggregation, AnalysisScore::getTotalSize)))
.addTextIf(formatBoldColumns(sum(aggregation, AnalysisScore::getImpact)), score.hasMaxScore())
sum(score, AnalysisScore::getErrorSize),
sum(score, AnalysisScore::getHighSeveritySize),
sum(score, AnalysisScore::getNormalSeveritySize),
sum(score, AnalysisScore::getLowSeveritySize),
sum(score, AnalysisScore::getTotalSize)))
.addTextIf(formatBoldColumns(sum(score, AnalysisScore::getImpact)), score.hasMaxScore())
.addNewline();
}

Expand All @@ -76,7 +76,7 @@ protected void createSpecificDetails(final AggregatedScore aggregation, final Li
}
}

private int sum(final AggregatedScore score, final Function<AnalysisScore, Integer> property) {
return score.getAnalysisScores().stream().map(property).reduce(Integer::sum).orElse(0);
private int sum(final AnalysisScore score, final Function<AnalysisScore, Integer> property) {
return score.getSubScores().stream().map(property).reduce(Integer::sum).orElse(0);
}
}
14 changes: 7 additions & 7 deletions src/main/java/edu/hm/hafner/grading/TestMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ protected void createSpecificDetails(final AggregatedScore aggregation,

if (score.getSubScores().size() > 1) {

Check warning on line 57 in src/main/java/edu/hm/hafner/grading/TestMarkdown.java

View check run for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 57 (ConditionalsBoundaryMutator)
Raw output
Survived mutations:
- changed conditional boundary (org.pitest.mutationtest.engine.gregor.mutators.ConditionalsBoundaryMutator)
details.addText(formatBoldColumns("Total",
sum(aggregation, TestScore::getPassedSize),
sum(aggregation, TestScore::getSkippedSize),
sum(aggregation, TestScore::getFailedSize),
sum(aggregation, TestScore::getTotalSize)))
.addTextIf(formatBoldColumns(sum(aggregation, TestScore::getImpact)), score.hasMaxScore())
sum(score, TestScore::getPassedSize),
sum(score, TestScore::getSkippedSize),
sum(score, TestScore::getFailedSize),
sum(score, TestScore::getTotalSize)))
.addTextIf(formatBoldColumns(sum(score, TestScore::getImpact)), score.hasMaxScore())
.addNewline();
}

Expand Down Expand Up @@ -123,7 +123,7 @@ private String getMessage(final TestCase issue) {
return issue.getMessage() + LINE_BREAK;
}

private int sum(final AggregatedScore score, final Function<TestScore, Integer> property) {
return score.getTestScores().stream().map(property).reduce(Integer::sum).orElse(0);
private int sum(final TestScore score, final Function<TestScore, Integer> property) {
return score.getSubScores().stream().map(property).reduce(Integer::sum).orElse(0);
}
}
28 changes: 21 additions & 7 deletions src/test/java/edu/hm/hafner/grading/AnalysisMarkdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,19 @@ void shouldShowScoreWithTwoResults() {
var analysisMarkdown = new AnalysisMarkdown();

assertThat(analysisMarkdown.createDetails(score))
.contains("Style - 30 of 100",
"|CheckStyle|1|2|3|4|10|30",
.contains("Style - 60 of 100",
"|CheckStyle 1|1|2|3|4|10|30",
"|CheckStyle 2|1|2|3|4|10|30",
"|**Total**|**2**|**4**|**6**|**8**|**20**|**60**",
"Bugs - 0 of 100",
"|SpotBugs|4|3|2|1|10|-120",
"|SpotBugs 1|4|3|2|1|10|-120",
"|SpotBugs 2|4|3|2|1|10|-120",
"|**Total**|**8**|**6**|**4**|**2**|**20**|**-240**",
":moneybag:|*1*|*2*|*3*|*4*|:heavy_minus_sign:|:heavy_minus_sign:",
":moneybag:|*-11*|*-12*|*-13*|*-14*|:heavy_minus_sign:|:heavy_minus_sign:");
assertThat(analysisMarkdown.createSummary(score))
.contains("- :warning: Style - 30 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"- :warning: Bugs - 0 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)")
.contains("- :warning: Style - 60 of 100: 20 warnings found (2 errors, 4 high, 6 normal, 8 low)",
"- :warning: Bugs - 0 of 100: 20 warnings found (8 errors, 6 high, 4 normal, 2 low)")
.doesNotContain("Total");
}

Expand All @@ -223,7 +227,12 @@ static AggregatedScore createScoreForTwoResults() {
"tools": [
{
"id": "checkstyle",
"name": "CheckStyle",
"name": "CheckStyle 1",
"pattern": "target/checkstyle.xml"
},
{
"id": "checkstyle",
"name": "CheckStyle 2",
"pattern": "target/checkstyle.xml"
}
],
Expand All @@ -238,7 +247,12 @@ static AggregatedScore createScoreForTwoResults() {
"tools": [
{
"id": "spotbugs",
"name": "SpotBugs",
"name": "SpotBugs 1",
"pattern": "target/spotbugsXml.xml"
},
{
"id": "spotbugs",
"name": "SpotBugs 2",
"pattern": "target/spotbugsXml.xml"
}
],
Expand Down
12 changes: 7 additions & 5 deletions src/test/java/edu/hm/hafner/grading/GradingReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,17 @@ void shouldCreateAnalysisResults() {

var score = AnalysisMarkdownTest.createScoreForTwoResults();
assertThat(results.getTextSummary(score)).isEqualTo(
"Autograding score - 30 of 200 (15%)");
"Autograding score - 60 of 200 (30%)");
assertThat(results.getMarkdownDetails(score)).contains(
"Autograding score - 30 of 200 (15%)",
"Autograding score - 60 of 200 (30%)",
"Unit Tests Score: not enabled",
"Code Coverage Score: not enabled",
"Mutation Coverage Score: not enabled",
"|CheckStyle|1|2|3|4|10|30",
"Style - 30 of 100",
"|SpotBugs|4|3|2|1|10|-120",
"|CheckStyle 1|1|2|3|4|10|30",
"|CheckStyle 2|1|2|3|4|10|30",
"Style - 60 of 100",
"|SpotBugs 1|4|3|2|1|10|-120",
"|SpotBugs 2|4|3|2|1|10|-120",
"Bugs - 0 of 100");
}

Expand Down
40 changes: 30 additions & 10 deletions src/test/java/edu/hm/hafner/grading/TestMarkdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,15 @@ void shouldShowNoImpactsWithTwoSubResults() {

static Node createTwoReports(final ToolConfiguration tool) {
if (tool.getId().equals("itest")) {
if (tool.getName().contains("2")) {
return TestScoreTest.createTestReport(5, 3, 4, "2nd-");
}
return TestScoreTest.createTestReport(5, 3, 4);
}
else if (tool.getId().equals("mtest")) {
if (tool.getName().contains("2")) {
return TestScoreTest.createTestReport(0, 0, 10, "2nd-");
}
return TestScoreTest.createTestReport(0, 0, 10);
}
throw new IllegalArgumentException("Unexpected tool ID: " + tool.getId());
Expand All @@ -199,7 +205,12 @@ void shouldShowScoreWithTwoResults() {
"tools": [
{
"id": "itest",
"name": "Integrationstests",
"name": "Integrationstests 1",
"pattern": "target/i-junit.xml"
},
{
"id": "itest",
"name": "Integrationstests 2",
"pattern": "target/i-junit.xml"
}
],
Expand All @@ -213,7 +224,12 @@ void shouldShowScoreWithTwoResults() {
"tools": [
{
"id": "mtest",
"name": "Modultests",
"name": "Modultests 1",
"pattern": "target/m-junit.xml"
},
{
"id": "mtest",
"name": "Modultests 2",
"pattern": "target/m-junit.xml"
}
],
Expand All @@ -231,10 +247,14 @@ void shouldShowScoreWithTwoResults() {

assertThat(testMarkdown.createDetails(score))
.containsIgnoringWhitespaces(
"One - 23 of 100",
"|Integrationstests|5|3|4|12|23",
"Two - 70 of 100",
"|Modultests|0|0|10|10|-30",
"One - 46 of 100",
"|Integrationstests 1|5|3|4|12|23",
"|Integrationstests 2|5|3|4|12|23",
"|**Total**|**10**|**6**|**8**|**24**|**46**",
"Two - 40 of 100",
"|Modultests 1|0|0|10|10|-30",
"|Modultests 2|0|0|10|10|-30",
"|**Total**|**0**|**0**|**20**|**20**|**-60**",
":moneybag:|*1*|*2*|*3*|:heavy_minus_sign:|:heavy_minus_sign:",
":moneybag:|*-1*|*-2*|*-3*|:heavy_minus_sign:|:heavy_minus_sign:",
"__test-class-failed-0:test-failed-0__",
Expand All @@ -249,10 +269,10 @@ void shouldShowScoreWithTwoResults() {
"```text StackTrace-2```");
assertThat(testMarkdown.createSummary(score))
.containsIgnoringWhitespaces(
"One - 23 of 100",
"4 tests failed, 5 passed, 3 skipped",
"Two - 70 of 100",
"10 tests failed, 0 passed");
"One - 46 of 100",
"8 tests failed, 10 passed, 6 skipped",
"Two - 40 of 100",
"20 tests failed, 0 passed");
}

@Test
Expand Down
24 changes: 14 additions & 10 deletions src/test/java/edu/hm/hafner/grading/TestScoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

import edu.hm.hafner.coverage.ClassNode;
import edu.hm.hafner.coverage.ModuleNode;
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.coverage.TestCase.TestCaseBuilder;
import edu.hm.hafner.coverage.TestCase.TestResult;
import edu.hm.hafner.grading.TestScore.TestScoreBuilder;
Expand Down Expand Up @@ -182,28 +182,32 @@ void shouldHandleOverflowWithPositiveImpact() {
.hasValue(50);
}

static Node createTestReport(final int passed, final int skipped, final int failed) {
var root = new ModuleNode(String.format("Tests (%d/%d/%d)", failed, skipped, passed));
static ModuleNode createTestReport(final int passed, final int skipped, final int failed) {
return createTestReport(passed, skipped, failed, StringUtils.EMPTY);
}

static ModuleNode createTestReport(final int passed, final int skipped, final int failed, final String prefix) {
var root = new ModuleNode(String.format("%sTests (%d/%d/%d)", prefix, failed, skipped, passed));
var tests = new ClassNode("Tests");
root.addChild(tests);

for (int i = 0; i < failed; i++) {
tests.addTestCase(new TestCaseBuilder()
.withTestName("test-failed-" + i)
.withClassName("test-class-failed-" + i)
.withMessage("failed-message-" + i)
.withDescription("StackTrace-" + i)
.withTestName(prefix + "test-failed-" + i)
.withClassName(prefix + "test-class-failed-" + i)
.withMessage(prefix + "failed-message-" + i)
.withDescription(prefix + "StackTrace-" + i)
.withStatus(TestResult.FAILED).build());
}
for (int i = 0; i < skipped; i++) {
tests.addTestCase(new TestCaseBuilder()
.withTestName("test-skipped-" + i)
.withClassName("test-class-skipped-" + i)
.withTestName(prefix + "test-skipped-" + i)
.withClassName(prefix + "test-class-skipped-" + i)
.withStatus(TestResult.SKIPPED).build());
}
for (int i = 0; i < passed; i++) {
tests.addTestCase(new TestCaseBuilder()
.withTestName("test-passed-" + i)
.withTestName(prefix + "test-passed-" + i)
.withStatus(TestResult.PASSED).build());
}

Expand Down

0 comments on commit 12fb07c

Please sign in to comment.