Majx is a test library for the JVM written in Kotlin that verifies that a JSON document fulfils your expectations regarding structure and values.
You provide two JSON documents
We try to let you express almost all of your expectations in a flexible, readable and concise way within the pattern. To achieve this, the pattern may contain magic values, that are treated in a certain way.
Obtain a reference to the actual and pattern JSONs as String
or jackson's JsonNode
and pass them to
Majx
provides which throw AssertionError
smatchesJson
from class IsMatchingJson
import static de.qaware.majx.Majx.assertJsonMatches;
import static de.qaware.majx.hamcrest.IsMatchingJson.matchesJson;
String actual = "{ \"greeting\" : \"Hello, World!\", \"id\" : 12 }";
String pattern = "{ \"greeting\" : \"Hello, World!\", \"id\" : \"...\" }";
assertJsonMatches(pattern, actual);
assertThat(actual, matchesJson(pattern); // or use the hamcrest matcher
This test would succeed for any value for the "id"
property inside the actual JSON
since its expected value is the magic "..."
-wildcard value in the pattern
(See Ignoring values).
Details on all available features can be found in the wiki:
The JARs are available via Maven Central
and JCenter.
If you are using Maven to build your project, add the following to the pom.xml
file.
<!-- https://mvnrepository.com/artifact/de.qaware.majx/majx -->
<dependency>
<groupId>de.qaware.majx</groupId>
<artifactId>majx</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
In case you are using Gradle to build your project, add the following to the build.gradle
file:
repositories {
jcenter()
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/de.qaware.majx/majx
testImplementation group: 'de.qaware.majx', name: 'majx', version: '1.3.1'
}
See Development Notes in the Wiki.
Claudius Boettcher, claudius.boettcher@qaware.de.
This software is provided under the MIT open source license, read the LICENSE
file for details.