Split or move testing-modules/junit-5 module (#7879)
This commit is contained in:
parent
2e030a63b7
commit
160fd28fdd
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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() {
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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)
|
|
@ -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>
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
|
@ -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() {
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.parameterized;
|
||||
package com.baeldung.junit5.parameterized;
|
||||
|
||||
public class Numbers {
|
||||
|
|
@ -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;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.parameterized;
|
||||
package com.baeldung.junit5.parameterized;
|
||||
|
||||
class Person {
|
||||
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.parameterized;
|
||||
package com.baeldung.junit5.parameterized;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.parameterized;
|
||||
package com.baeldung.junit5.parameterized;
|
||||
|
||||
class Strings {
|
||||
|
|
@ -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));
|
||||
}
|
|
@ -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;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.parameterized;
|
||||
package com.baeldung.junit5.parameterized;
|
||||
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
|
|
@ -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;
|
|
@ -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)
|
||||
|
|
|
@ -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() {
|
|
@ -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")
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue