Using Core
Installing
To install Diferencia Java JUnit 5 you need to add JUnit 5
and Diferencia JUnit 5
dependencies on your build tool.
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>
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
In this case it is using OkHttp to send to the Diferencia proxy a Of course you can use any other HttpClient to validate the compatibility such as REST-assured. |