Unit Testing

Embedded Cassandra JUnit5 Test

com.github.nosan : embedded-cassandra-junit5-test

Embedded Cassandra JUnit5 Test. This module contains Embedded Cassandra JUnit5 classes.

Last Version: 3.1.0

Release Date:

Last Version: 0.1.0

Release Date:

USpek

pl.mareklangiewicz : uspekx-junit4-jvm

Micro tool for testing with syntax similar to Spek, but shorter.

Last Version: 0.0.24

Release Date:

Last Version: 1.6.6

Release Date:

pact-jvm-consumer-junit5

au.com.dius : pact-jvm-consumer-junit5

pact-jvm-consumer-junit5 ======================== JUnit 5 support for Pact consumer tests ## Dependency The library is available on maven central using: * group-id = `au.com.dius` * artifact-id = `pact-jvm-consumer-junit5` * version-id = `4.0.x` ## Usage ### 1. Add the Pact consumer test extension to the test class. To write Pact consumer tests with JUnit 5, you need to add `@ExtendWith(PactConsumerTestExt)` to your test class. This replaces the `PactRunner` used for JUnit 4 tests. The rest of the test follows a similar pattern as for JUnit 4 tests. ```java @ExtendWith(PactConsumerTestExt.class) class ExampleJavaConsumerPactTest { ``` ### 2. create a method annotated with `@Pact` that returns the interactions for the test For each test (as with JUnit 4), you need to define a method annotated with the `@Pact` annotation that returns the interactions for the test. ```java @Pact(provider="ArticlesProvider", consumer="test_consumer") public RequestResponsePact createPact(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("ExampleJavaConsumerPactTest test interaction") .path("/articles.json") .method("GET") .willRespondWith() .status(200) .body("{\"responsetest\": true}") .toPact(); } ``` ### 3. Link the mock server with the interactions for the test with `@PactTestFor` Then the final step is to use the `@PactTestFor` annotation to tell the Pact extension how to setup the Pact test. You can either put this annotation on the test class, or on the test method. For examples see [ArticlesTest](src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java) and [MultiTest](src/test/groovy/au/com/dius/pact/consumer/junit5/MultiTest.groovy). The `@PactTestFor` annotation allows you to control the mock server in the same way as the JUnit 4 `PactProviderRule`. It allows you to set the hostname to bind to (default is `localhost`) and the port (default is to use a random port). You can also set the Pact specification version to use (default is V3). ```java @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "ArticlesProvider") public class ExampleJavaConsumerPactTest { ``` **NOTE on the hostname**: The mock server runs in the same JVM as the test, so the only valid values for hostname are: | hostname | result | | -------- | ------ | | `localhost` | binds to the address that localhost points to (normally the loopback adapter) | | `127.0.0.1` or `::1` | binds to the loopback adapter | | host name | binds to the default interface that the host machines DNS name resolves to | | `0.0.0.0` or `::` | binds to the all interfaces on the host machine | #### Matching the interactions by provider name If you set the `providerName` on the `@PactTestFor` annotation, then the first method with a `@Pact` annotation with the same provider name will be used. See [ArticlesTest](src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java) for an example. #### Matching the interactions by method name If you set the `pactMethod` on the `@PactTestFor` annotation, then the method with the provided name will be used (it still needs a `@Pact` annotation). See [MultiTest](src/test/groovy/au/com/dius/pact/consumer/junit5/MultiTest.groovy) for an example. ### Injecting the mock server into the test You can get the mock server injected into the test method by adding a `MockServer` parameter to the test method. ```java @Test void test(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/articles.json").execute().returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(equalTo(200))); } ``` This helps with getting the base URL of the mock server, especially when a random port is used. ## Changing the directory pact files are written to By default, pact files are written to `target/pacts` (or `build/pacts` if you use Gradle), but this can be overwritten with the `pact.rootDir` system property. This property needs to be set on the test JVM as most build tools will fork a new JVM to run the tests. For Gradle, add this to your build.gradle: ```groovy test { systemProperties['pact.rootDir'] = "$buildDir/custom-pacts-directory" } ``` For maven, use the systemPropertyVariables configuration: ```xml <project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18</version> <configuration> <systemPropertyVariables> <pact.rootDir>some/other/directory</pact.rootDir> <buildDirectory>${project.basedir}/target</buildDirectory> [...] </systemPropertyVariables> </configuration> </plugin> </plugins> </build> [...] </project> ``` For SBT: ```scala fork in Test := true, javaOptions in Test := Seq("-Dpact.rootDir=some/other/directory") ``` ### Using `@PactFolder` annotation You can override the directory the pacts are written in a test by adding the `@PactFolder` annotation to the test class. ## Forcing pact files to be overwritten (3.6.5+) By default, when the pact file is written, it will be merged with any existing pact file. To force the file to be overwritten, set the Java system property `pact.writer.overwrite` to `true`. ## Unsupported The current implementation does not support tests with multiple providers. This will be added in a later release. # Having values injected from provider state callbacks (3.6.11+) You can have values from the provider state callbacks be injected into most places (paths, query parameters, headers, bodies, etc.). This works by using the V3 spec generators with provider state callbacks that return values. One example of where this would be useful is API calls that require an ID which would be auto-generated by the database on the provider side, so there is no way to know what the ID would be beforehand. The following DSL methods all you to set an expression that will be parsed with the values returned from the provider states: For JSON bodies, use `valueFromProviderState`.<br/> For headers, use `headerFromProviderState`.<br/> For query parameters, use `queryParameterFromProviderState`.<br/> For paths, use `pathFromProviderState`. For example, assume that an API call is made to get the details of a user by ID. A provider state can be defined that specifies that the user must be exist, but the ID will be created when the user is created. So we can then define an expression for the path where the ID will be replaced with the value returned from the provider state callback. ```java .pathFromProviderState("/api/users/au.com.dius:pact-jvm-consumer-junit5:jar:4.0.10", "/api/users/100") ``` You can also just use the key instead of an expression: ```java .valueFromProviderState('userId', 'userId', 100) // will look value using userId as the key ```

Last Version: 4.0.10

Release Date:

JUnited :: FlywayDB

com.crosstreelabs : junited.flyway

Adds flyway support during tests

Last Version: 0.1.0

Release Date:

Last Version: 0.4.5

Release Date:

Apache Tuscany SCA Samples JUnit

org.apache.tuscany.sca.samples : junit

The Apache Software Foundation provides support for the Apache community of open-source software projects. The Apache projects are characterized by a collaborative, consensus based development process, an open and pragmatic software license, and a desire to create high quality software that leads the way in its field. We consider ourselves not simply a group of projects sharing a server, but rather a community of developers and users.

Last Version: 2.0

Release Date:

Junit Database Cleaner Extension

pro.vdshb : junit-db-cleaner-extension

Junit extension that helps to clean database before tests. Only PostgreSQL DB is supported yet.

Last Version: 0.5

Release Date:

rx-junit5-providers

io.vertx : rx-junit5-providers

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

Last Version: 4.0.0-milestone5

Release Date:

Last Version: 0.8.0

Release Date:

Testify Project JUnit4 Spring Integration Test Archetype

org.testifyproject.archetypes : junit-spring-integrationtest-archetype

Creates a new quickstart project to integration test Spring modules with Testify, JUnit4, Mockito, and AssertJ.

Last Version: 1.0.0

Release Date:

junit-quickcheck

com.pholser : junit-quickcheck

Property-based testing, JUnit-style

Last Version: 1.0

Release Date:

Last Version: 0.3.1

Release Date:

com.github.automatedowl:chromedriver-js-errors-collector-junit

com.github.automatedowl : chromedriver-js-errors-collector-junit

Java library which allows to easily collect JS errors received in Chromedriver session, using annotations on test methods.

Last Version: 1.0.4

Release Date:

android-junit4-test

com.uphyca : android-junit4-test

Tools for Android testing with JUnit4

Last Version: 0.5

Release Date:

ecFeed

com.ecfeed : ecfeed.junit

An open library used to connect to the ecFeed service. It can be also used as a standalone testing tool. It is integrated with Junit5 and generates a stream of test cases using a selected algorithm (e.g. Cartesian, N-Wise). There are no limitations associated with the off-line version but the user cannot access the on-line computation servers and the model database.

Last Version: 1.0.0

Release Date:

junit-utils

org.ow2.odis : junit-utils

JUnit test utilities

Last Version: 0.0.2

Release Date:

Last Version: 0.0.3

Release Date:

kevinarpe-papaya-testing-junit

com.googlecode.kevinarpe-papaya : kevinarpe-papaya-testing-junit

Papaya for Testing with JUnit: Utilities for Java 1.6+ written by Kevin Connor ARPE

Last Version: 0.0.15

Release Date:

value-provider-junit4

com.tngtech.valueprovider : value-provider-junit4

JUnit 4 test infrastructure to reproduce random test data in case of test failures.

Last Version: 1.1.0

Release Date:

SauceBindings JUnit4

com.saucelabs : saucebindings-junit4

Provides tools for interacting with SauceLabs with JUnit 4

Last Version: 1.0.1

Release Date:

Last Version: 1.0.1

Release Date:

Last Version: 1.0.7

Release Date:

pact-jvm-provider-junit5_2.12

au.com.dius : pact-jvm-provider-junit5_2.12

# Pact Junit 5 Extension ## Overview For writing Pact verification tests with JUnit 5, there is an JUnit 5 Invocation Context Provider that you can use with the `@TestTemplate` annotation. This will generate a test for each interaction found for the pact files for the provider. To use it, add the `@Provider` and one of the pact source annotations to your test class (as per a JUnit 4 test), then add a method annotated with `@TestTemplate` and `@ExtendWith(PactVerificationInvocationContextProvider.class)` that takes a `PactVerificationContext` parameter. You will need to call `verifyInteraction()` on the context parameter in your test template method. For example: ```java @Provider("myAwesomeService") @PactFolder("pacts") public class ContractVerificationTest { @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } } ``` For details on the provider and pact source annotations, refer to the [Pact junit runner](../pact-jvm-provider-junit/README.md) docs. ## Test target You can set the test target (the object that defines the target of the test, which should point to your provider) on the `PactVerificationContext`, but you need to do this in a before test method (annotated with `@BeforeEach`). There are three different test targets you can use: `HttpTestTarget`, `HttpsTestTarget` and `AmpqTestTarget`. For example: ```java @BeforeEach void before(PactVerificationContext context) { context.setTarget(HttpTestTarget.fromUrl(new URL(myProviderUrl))); // or something like // context.setTarget(new HttpTestTarget("localhost", myProviderPort, "/")); } ``` **Note for Maven users:** If you use Maven to run your tests, you will have to make sure that the Maven Surefire plugin is at least version 2.22.1 uses an isolated classpath. For example, configure it by adding the following to your POM: ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> <configuration> <useSystemClassLoader>false</useSystemClassLoader> </configuration> </plugin> ``` ## Provider State Methods Provider State Methods work in the same way as with JUnit 4 tests, refer to the [Pact junit runner](../pact-jvm-provider-junit/README.md) docs. ### Using multiple classes for the state change methods If you have a large number of state change methods, you can split things up by moving them to other classes. You will need to specify the additional classes on the test context in a `Before` method. Do this with the `withStateHandler` or `setStateHandlers` methods. See [StateAnnotationsOnAdditionalClassTest](pact-jvm-provider-junit5/src/test/java/au/com/dius/pact/provider/junit5/StateAnnotationsOnAdditionalClassTest.java) for an example. ## Modifying the requests before they are sent **Important Note:** You should only use this feature for things that can not be persisted in the pact file. By modifying the request, you are potentially modifying the contract from the consumer tests! Sometimes you may need to add things to the requests that can't be persisted in a pact file. Examples of these would be authentication tokens, which have a small life span. The Http and Https test targets support injecting the request that will executed into the test template method. You can then add things to the request before calling the `verifyInteraction()` method. For example to add a header: ```java @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(PactVerificationContext context, HttpRequest request) { // This will add a header to the request request.addHeader("X-Auth-Token", "1234"); context.verifyInteraction(); } ``` ## Objects that can be injected into the test methods You can inject the following objects into your test methods (just like the `PactVerificationContext`). They will be null if injected before the supported phase. | Object | Can be injected from phase | Description | | ------ | --------------- | ----------- | | PactVerificationContext | @BeforeEach | The context to use to execute the interaction test | | Pact | any | The Pact model for the test | | Interaction | any | The Interaction model for the test | | HttpRequest | @TestTemplate | The request that is going to be executed (only for HTTP and HTTPS targets) | | ProviderVerifier | @TestTemplate | The verifier instance that is used to verify the interaction |

Last Version: 3.6.15

Release Date:

spf4j-slf4j-test-junit5

org.spf4j : spf4j-slf4j-test-junit5

A slf4j backend for your unit tests

Last Version: 8.9.5

Release Date:

org.eclipse.jdt.junit4.runtime

com.github.adedayo.eclipse.sdk : org.eclipse.jdt.junit4.runtime

A packaging of the eclipse sdk org.eclipse.jdt.junit4.runtime library.

Last Version: 1.1.500

Release Date:

Last Version: 0.4.4

Release Date:

Last Version: 4.5.1

Release Date:

junit-toolbox

org.codeartisans : junit-toolbox

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

Last Version: 1.0

Release Date:

org.junit:junit4-runner

org.junit : junit4-runner

Module "junit4-runner" of JUnit 5.

Last Version: 5.0.0-ALPHA

Release Date:

Geb for JUnit 5

org.gebish : geb-junit5

Geb (pronounced "jeb") integration with the JUnit 5 test framework.

Last Version: 5.1

Release Date:

Last Version: 0.1.2

Release Date:

Flink-JUnit

com.github.knaufk : flink-junit_2.11

This is a small, easy-to-use, yet flexible JUnit Rule, which spins up and tears down an Apache Flink cluster for integration tests.

Last Version: 0.5

Release Date:

archetype-java-junit

io.github.manedev79 : archetype-java-junit

Maven archetype with recent java version, JUnit5, assertj and git repository in place.

Last Version: 1.0.1

Release Date:

Last Version: 0.0.2

Release Date:

Last Version: 5.0.0-M4

Release Date:

Last Version: 4.3.4

Release Date:

Last Version: 1.5.0

Release Date:

integration-test-junit5

io.toolisticon.cute : integration-test-junit5

Please refer to https://github.com/toolisticon/cute

Last Version: 0.12.0

Release Date:

Last Version: 0.6.1

Release Date: