Skip to content

Instantly share code, notes, and snippets.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version> 
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<groups>includeTag</groups>
  <excludedGroups>excludeTag</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<properties>
<excludeTags>excludeTag</excludeTags>
<includeTags>includeTag</includeTags>
</properties>
</configuration>
@ExtendWith(MockitoExtension.class)
public class TestMockitoInjection {
private BoringService service;
public TestMockitoInjection(@Mock BoringService service) {
this.service = service;
}
@Test
public void testConstructorInjectedValue() {
public class TestAssertJSoftAssertions {
@Test
public void testSoftAssertions() {
Person person = new Person("John", "Doe");
SoftAssertions softly = new SoftAssertions();
softly.assertThat(person.getFName()).isEqualTo("Anonymous");
softly.assertThat(person.getLName()).isEqualTo("Person");
softly.assertAll();
}
public class ConsoleOutputListener implements TestExecutionListener {
@Override
public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry entry) {
entry.getKeyValuePairs().values().stream().forEach(c -> System.out.println("Captured output: " + c));
TestExecutionListener.super.reportingEntryPublished(testIdentifier, entry);
}
}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<properties>
<configurationParameters>
junit.platform.output.capture.stdout=true
junit.platform.output.capture.stderr=true
</configurationParameters>
<!-- New aggregate dependency -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- Old dependencies -->
<!-- <dependency> -->
<!-- <groupId>org.junit.jupiter</groupId> -->
<!-- <artifactId>junit-jupiter-api</artifactId> -->
@ContextConfiguration(classes = { HotelApplication.class }, initializers = ITCustomerJUnit5Repo.Initializer.class)
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
@TestMethodOrder(OrderAnnotation.class)
public class ITCustomerJUnit5Repo {
//Removed code, for clarity
@Test
@Order(1)
public void testCountNumberOfCustomersInDB() {
@TestMethodOrder(OrderAnnotation.class)
public class TestTempDir {
@Test
@Order(1)
public void workInMethod(@TempDir Path tempPathArg) throws IOException {
File temp = tempPathArg.resolve("temp.txt").toFile();
FileUtils.write(temp, "temp contents", StandardCharsets.ISO_8859_1);
assertEquals("temp contents", FileUtils.readFileToString(temp, StandardCharsets.ISO_8859_1));