-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add flakes to the failsafe-summary.xml. Fix a bug in the equals metho… #1
base: master
Are you sure you want to change the base?
Changes from all commits
5f3d378
01faf7f
8aaf0a6
eab72b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,17 @@ | |
package org.apache.maven.plugin.failsafe; | ||
|
||
import java.io.File; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Locale; | ||
|
||
import org.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils; | ||
import org.apache.maven.surefire.api.suite.RunResult; | ||
import org.apache.maven.surefire.api.util.SureFireFileManager; | ||
import org.junit.Test; | ||
|
||
import static java.lang.String.format; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
|
@@ -64,6 +69,49 @@ public void testSkipped() throws Exception { | |
writeReadCheck(new RunResult(3, 2, 1, 0, null, true)); | ||
} | ||
|
||
@Test | ||
public void testFlakes() throws Exception { | ||
writeReadCheck(new RunResult(3, 2, 1, 0, 2, null, true)); | ||
} | ||
|
||
@Test | ||
public void testLegacyDeserialization() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this test to check for backwards compatibility. It ensures that failsafe-summary.xml files produced by older versions of the plugin (i.e without the flakes field) can still be read into memory. In these cases, we simply set flakes to 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love your work. |
||
File legacySummary = SureFireFileManager.createTempFile("failsafe", "test"); | ||
String legacyFailsafeSummaryXmlTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
+ "<failsafe-summary xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" | ||
+ " xsi:noNamespaceSchemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/failsafe-summary.xsd\"" | ||
+ " result=\"%s\" timeout=\"%s\">\n" | ||
+ " <completed>%d</completed>\n" | ||
+ " <errors>%d</errors>\n" | ||
+ " <failures>%d</failures>\n" | ||
+ " <skipped>%d</skipped>\n" | ||
+ " %s\n" | ||
+ "</failsafe-summary>"; | ||
String xml = format(Locale.ROOT, legacyFailsafeSummaryXmlTemplate, 0, false, 3, 2, 1, 0, "msg"); | ||
Files.write( | ||
legacySummary.toPath(), | ||
xml.getBytes(StandardCharsets.UTF_8), | ||
StandardOpenOption.CREATE, | ||
StandardOpenOption.TRUNCATE_EXISTING, | ||
StandardOpenOption.WRITE); | ||
|
||
// When the failsafe-summary.xml does not contain the <flakes> element, it should be considered as 0. | ||
RunResult expected = new RunResult(3, 2, 1, 0, 0, null, false); | ||
RunResult actual = FailsafeSummaryXmlUtils.toRunResult(legacySummary); | ||
|
||
assertThat(actual.getCompletedCount()).isEqualTo(expected.getCompletedCount()); | ||
|
||
assertThat(actual.getErrors()).isEqualTo(expected.getErrors()); | ||
|
||
assertThat(actual.getFailures()).isEqualTo(expected.getFailures()); | ||
|
||
assertThat(actual.getSkipped()).isEqualTo(expected.getSkipped()); | ||
|
||
assertThat(actual.getFlakes()).isEqualTo(expected.getFlakes()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unnecessary empty lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only did this to be consistent with the person who wrote the other test in this file 😆 |
||
assertThat(actual).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void testAppendSerialization() throws Exception { | ||
RunResult simpleAggregate = getSimpleAggregate(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.apache.maven.plugins.surefire</groupId> | ||
<artifactId>surefire-junit-testtemplate-retry-bug</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>Test for JUnit 5 TestTemplate with retries</name> | ||
|
||
<properties> | ||
<maven.compiler.source>${java.specification.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.specification.version}</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>${junit5.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<version>${junit5.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire.version}</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package pkg; | ||
|
||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.Extension; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext; | ||
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class FieldSettingTest { | ||
private int testValue = 42; | ||
|
||
// We're calling this in the provider underneath | ||
public void setTestValue(int testValue) { | ||
this.testValue = testValue; | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(FieldSettingContextProvider.class) | ||
public void testTemplatePartiallyFails() { | ||
assertEquals(42, testValue); | ||
} | ||
} | ||
|
||
|
||
class FieldSettingContextProvider implements TestTemplateInvocationContextProvider { | ||
@Override | ||
public boolean supportsTestTemplate(ExtensionContext extensionContext) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext extensionContext) { | ||
return Stream.of(context(0), context(42)); | ||
} | ||
|
||
private TestTemplateInvocationContext context(int parameter) { | ||
return new TestTemplateInvocationContext() { | ||
@Override | ||
public String getDisplayName(int invocationIndex) { | ||
return "[%d] %s".formatted(invocationIndex, parameter); | ||
} | ||
|
||
@Override | ||
public List<Extension> getAdditionalExtensions() { | ||
return getBeforeEachCallbacks(parameter); | ||
} | ||
}; | ||
} | ||
|
||
private List<Extension> getBeforeEachCallbacks(int value) { | ||
return List.of(((BeforeEachCallback) ctx -> | ||
((FieldSettingTest) ctx.getRequiredTestInstance()).setTestValue(value) | ||
)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package pkg; | ||
|
||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.Extension; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.api.extension.ParameterResolver; | ||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext; | ||
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ParamsContextTest { | ||
|
||
@TestTemplate | ||
@ExtendWith(ParamsContextProvider.class) | ||
void testTemplatePartiallyFails(Integer value) { | ||
assertEquals(42, value); | ||
} | ||
} | ||
|
||
class ParamsContextProvider implements TestTemplateInvocationContextProvider { | ||
|
||
@Override | ||
public boolean supportsTestTemplate(ExtensionContext context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { | ||
return Stream.of(invocationContext(0), invocationContext(42)); | ||
} | ||
|
||
private TestTemplateInvocationContext invocationContext(int parameter) { | ||
return new TestTemplateInvocationContext() { | ||
@Override | ||
public String getDisplayName(int invocationIndex) { | ||
return "[%d] %s".formatted(invocationIndex, parameter); | ||
} | ||
|
||
@Override | ||
public List<Extension> getAdditionalExtensions() { | ||
return Collections.singletonList(new ParameterResolver() { | ||
@Override | ||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { | ||
return parameterContext.getParameter().getType().equals(Integer.class); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { | ||
return parameter; | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not a problem:
What happens when you don't put flakes in the xml string? Does this fail well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/atlassian-forks/maven-surefire/pull/1/files#diff-5bf0b71acbf01d365bb28569f502903f8cb33d96ec98b0c1c53bab5a5aa7ee5fR95
Yeah; this function doesn't throw when the field isn't present. It will just return a blank string (and I'm handling that case in the linked line of code). We'll set flakes = 0 when the flakes XML element isn't present.