Split or move testing-modules/junit-5 module (#7879)

This commit is contained in:
Catalin Burcea 2019-10-03 06:33:18 +03:00 committed by Josh Cummings
parent 2e030a63b7
commit 160fd28fdd
44 changed files with 176 additions and 46 deletions

View File

@ -1,14 +1,8 @@
### Relevant Articles:
- [A Guide to @RepeatedTest in Junit 5](http://www.baeldung.com/junit-5-repeated-test)
- [Guide to Dynamic Tests in Junit 5](http://www.baeldung.com/junit5-dynamic-tests)
- [A Guide to JUnit 5 Extensions](http://www.baeldung.com/junit-5-extensions)
- [Inject Parameters into JUnit Jupiter Unit Tests](http://www.baeldung.com/junit-5-parameters)
- [Mockito and JUnit 5 Using ExtendWith](http://www.baeldung.com/mockito-junit-5-extension)
- [JUnit5 Programmatic Extension Registration with @RegisterExtension](http://www.baeldung.com/junit-5-registerextension-annotation)
- [The Order of Tests in JUnit](http://www.baeldung.com/junit-5-test-order)
- [A Guide to JUnit 5 Extensions](https://www.baeldung.com/junit-5-extensions)
- [Inject Parameters into JUnit Jupiter Unit Tests](https://www.baeldung.com/junit-5-parameters)
- [Mockito and JUnit 5 Using ExtendWith](https://www.baeldung.com/mockito-junit-5-extension)
- [The Order of Tests in JUnit](https://www.baeldung.com/junit-5-test-order)
- [Running JUnit Tests Programmatically, from a Java Application](https://www.baeldung.com/junit-tests-run-programmatically-from-java)
- [Testing an Abstract Class With JUnit](https://www.baeldung.com/junit-test-abstract-class)
- [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng)
- [Guide to JUnit 5 Parameterized Tests](https://www.baeldung.com/parameterized-tests-junit-5)
- [JUnit 5 Conditional Test Execution with Annotations](https://www.baeldung.com/junit-5-conditional-test-execution)
- [Assertions in JUnit 4 and JUnit 5](http://www.baeldung.com/junit-assertions)
- [Guide to Dynamic Tests in Junit 5](https://www.baeldung.com/junit5-dynamic-tests)

View File

@ -26,11 +26,6 @@
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>

View File

@ -1,4 +1,4 @@
package com.baeldung;
package com.baeldung.dynamictests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -17,10 +17,8 @@ import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.function.ThrowingConsumer;
import com.baeldung.helpers.Employee;
import com.baeldung.helpers.EmployeeDao;
public class DynamicTestsExample {
public class DynamicTestsUnitTest {
@TestFactory
Collection<DynamicTest> dynamicTestsWithCollection() {

View File

@ -0,0 +1,38 @@
package com.baeldung.dynamictests;
public class Employee {
private long id;
private String firstName;
public Employee(long id) {
this.id = id;
this.firstName = "";
}
public Employee(long id, String firstName) {
this.id = id;
this.firstName = firstName;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Override
public String toString() {
return "Employee [id=" + id + ", firstName=" + firstName + "]";
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.dynamictests;
public class EmployeeDao {
public Employee save(long id) {
return new Employee(id);
}
public Employee save(long id, String firstName) {
return new Employee(id, firstName);
}
public Employee update(Employee employee) {
return employee;
}
}

View File

@ -0,0 +1,9 @@
## Junit 5 Annotations
This module contains articles about Junit 5 Annotations
### Relevant Articles:
- [A Guide to @RepeatedTest in Junit 5](https://www.baeldung.com/junit-5-repeated-test)
- [JUnit 5 Conditional Test Execution with Annotations](https://www.baeldung.com/junit-5-conditional-test-execution)
- [JUnit5 Programmatic Extension Registration with @RegisterExtension](https://www.baeldung.com/junit-5-registerextension-annotation)
- [Guide to JUnit 5 Parameterized Tests](https://www.baeldung.com/parameterized-tests-junit-5)

View File

@ -0,0 +1,57 @@
<?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>
<artifactId>junit5-annotations</artifactId>
<version>1.0-SNAPSHOT</version>
<name>junit5-annotations</name>
<description>Intro to JUnit 5</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<junit.jupiter.version>5.4.2</junit.jupiter.version>
<junit.platform.version>1.4.2</junit.platform.version>
<log4j2.version>2.8.2</log4j2.version>
</properties>
</project>

View File

@ -0,0 +1,18 @@
package com.baeldung.junit5.registerextension;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
public class LoggingExtension implements TestInstancePostProcessor {
@Override
public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
Logger logger = LogManager.getLogger(testInstance.getClass());
testInstance.getClass()
.getMethod("setLogger", Logger.class)
.invoke(testInstance, logger);
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.extensions;
package com.baeldung.junit5.registerextension;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;

View File

@ -1,4 +1,4 @@
package com.baeldung;
package com.baeldung.junit5;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -8,7 +8,7 @@ import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.RepetitionInfo;
import org.junit.jupiter.api.TestInfo;
public class RepeatedTestExample {
public class RepeatedTestAnnotationUnitTest {
@BeforeEach
void beforeEachTest() {

View File

@ -1,4 +1,4 @@
package com.baeldung.conditional;
package com.baeldung.junit5.conditional;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.converter.ConvertWith;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
public class Numbers {

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
class Person {

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.aggregator.AggregateWith;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.params.converter.ArgumentConversionException;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import java.util.stream.Stream;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
class Strings {

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;
@ -44,7 +44,7 @@ class StringsUnitTest {
}
@ParameterizedTest
@MethodSource("com.baeldung.parameterized.StringParams#blankStrings")
@MethodSource("com.baeldung.junit5.parameterized.StringParams#blankStrings")
void isBlank_ShouldReturnTrueForNullOrBlankStringsExternalSource(String input) {
assertTrue(Strings.isBlank(input));
}

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;

View File

@ -1,4 +1,4 @@
package com.baeldung.parameterized;
package com.baeldung.junit5.parameterized;
import org.junit.jupiter.params.provider.ArgumentsSource;

View File

@ -1,6 +1,6 @@
package com.baeldung;
package com.baeldung.junit5.registerextension;
import com.baeldung.extensions.RegisterExtensionSampleExtension;
import com.baeldung.junit5.registerextension.RegisterExtensionSampleExtension;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

View File

@ -1,2 +1,6 @@
This is the code for the Junit 4 - Junit 5 Migration E-book.
### Relevant Articles:
- [Junit 5 Migration](https://www.baeldung.com/junit-5-migration)
- [A Quick JUnit vs TestNG Comparison](https://www.baeldung.com/junit-vs-testng)
- [Assertions in JUnit 4 and JUnit 5](https://www.baeldung.com/junit-assertions)

View File

@ -1,4 +1,4 @@
package com.baeldung.junit;
package com.baeldung.junit5vsjunit4assertions;
import org.junit.Test;
@ -10,7 +10,7 @@ import static org.junit.Assert.*;
/**
* Unit test that demonstrate the different assertions available within JUnit 4
*/
public class AssertionsUnitTest {
public class Junit4AssertionsUnitTest {
@Test
public void whenAssertingEquality_thenEqual() {

View File

@ -1,4 +1,4 @@
package com.baeldung;
package com.baeldung.junit5vsjunit4assertions;
import static java.time.Duration.ofSeconds;
import static java.util.Arrays.asList;
@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test;
* Unit test that demonstrate the different assertions available within JUnit 4
*/
@DisplayName("Test case for assertions")
public class AssertionUnitTest {
public class Junit5AssertionsUnitTest {
@Test
@DisplayName("Arrays should be equals")

View File

@ -19,6 +19,7 @@
<module>gatling</module>
<module>groovy-spock</module>
<module>junit-5</module>
<module>junit5-annotations</module>
<module>junit5-migration</module>
<module>load-testing-comparison</module>
<module>mockito</module>