Using Core

Installing

To install Diferencia Java JUnit 5 you need to add JUnit 5 and Diferencia JUnit 5 dependencies on your build tool.

For now Diferencia is released in jcenter but in near future will be released in Maven central as well.

pom.xml
<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>bintray</name>
        <url>https://jcenter.bintray.com</url>
    </repository>
</repositories>

Maven

pom.xml
<dependency>
    <groupId>com.lordofthejars.diferencia</groupId>
    <artifactId>diferencia-java-junit</artifactId>
    <version>${version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.2.0</version>
    <scope>test</scope>
</dependency>

Gradle

build.gradle
testCompile "com.lordofthejars.diferencia:diferencia-java-junit:${version}"
testCompile('org.junit.jupiter:junit-jupiter-api:5.2.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.2.0')

Code Example

The Extension class to be used is com.lordofthejars.diferencia.junit.DiferenciaExtension which is the one responsible for managing the lifecycle of Diferencia and provides the parameter resolver.

DiferenciaExtensionTest.java
@ExtendWith(DiferenciaExtension.class) (1)
@DiferenciaCore(primary = "http://now.httpbin.org",
                candidate = "http://now.httpbin.org", (2)
    config = @DiferenciaConfig(noiseDetection = true,
                               secondary = "http://now.httpbin.org")) (3)
public class DiferenciaExtensionTest {

    @Test
    public void should_detect_any_possible_regression(Diferencia diferencia) (4)
            throws IOException {

        final String diferenciaUrl = diferencia.getDiferenciaUrl(); (5)
        final Response response = sendRequest(diferenciaUrl, "/");
        assertThat(response.code()).isEqualTo(HttpURLConnection.HTTP_OK); (6)

    }
}
1 Diferencia extension registration.
2 Defines primary and candidate URLs.
3 Configures Diferencia with extra parameters.
4 Injects Diferencia object in test method.
5 Gets URL to send requests.
6 In this case both responses are different but with noise detection so they should pass.
About sending requests

sendRequest is a helper method created in the test to send request to Diferencia.

In this case it is using OkHttp to send to the Diferencia proxy a GET request to / path. Internally Diferencia will duplicate this call to the primary and to the candidate, compare both responses and send back the result.

Of course you can use any other HttpClient to validate the compatibility such as REST-assured.