JSONAssert alternatives and similar libraries
Based on the "Testing" category.
Alternatively, view JSONAssert alternatives based on common mentions on social networks and blogs.
-
Mockito
Most popular Mocking framework for unit tests written in Java -
TestContainers
Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. -
MockServer
MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). -
PowerMock
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable. -
Awaitility
Awaitility is a small Java DSL for synchronizing asynchronous operations -
AssertJ
AssertJ is a library providing easy to use rich typed assertions -
ArchUnit
A Java architecture test library, to specify and assert architecture rules in plain Java -
Pact JVM
JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project. -
Selenium
Portable software testing framework for web applications. -
JMockit
Advanced Java library for integration testing, mocking, faking, and code coverage -
System Rules
A collection of JUnit rules for testing code which uses java.lang.System. -
Citrus
Framework for automated integration tests with focus on messaging integration -
ConcurrentUnit
Toolkit for testing multi-threaded and asynchronous applications -
junit-dataprovider
A TestNG like dataprovider runner for JUnit with many additional features -
Jukito
The combined power of JUnit, Guice and Mockito. Plus it sounds like a cool martial art. -
Mutability Detector
Lightweight analysis tool for detecting mutability in Java classes -
Lamdba Behave
A modern testing and behavioural specification framework for Java 8 -
Arquillian
Integration and functional testing platform for Java EE containers. -
Randomized Testing
Randomized Testing (Core JUnit Runner, ANT, Maven) -
Spectrum
A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber. -
Scott Test Reporter
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java -
raml-tester
Test if a request/response matches a given raml definition -
pojo-tester
Java testing framework for testing pojo methods. It tests equals, hashCode, toString, getters, setters, constructors and whatever you report in issues ;) -
J8Spec
Library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine.
Developer Ecosystem Survey 2022
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of JSONAssert or a related project?
README
JSONassert
Write JSON unit tests in less code. Great for testing REST interfaces.
Summary
Write JSON tests as if you are comparing a string. Under the covers, JSONassert converts your string into a JSON object and compares the logical structure and data with the actual JSON. When strict is set to false (recommended), it forgives reordering data and extending results (as long as all the expected elements are there), making tests less brittle.
Supported test frameworks:
Examples
In JSONassert you write and maintain something like this:
JSONObject data = getRESTData("/friends/367.json");
String expected = "{friends:[{id:123,name:\"Corby Page\"},{id:456,name:\"Carter Page\"}]}";
JSONAssert.assertEquals(expected, data, false);
instead of all this:
JSONObject data = getRESTData("/friends/367.json"); Assert.assertTrue(data.has("friends")); Object friendsObject = data.get("friends"); Assert.assertTrue(friendsObject instanceof JSONArray); JSONArray friends = (JSONArray) friendsObject; Assert.assertEquals(2, data.length()); JSONObject friend1Obj = friends.getJSONObject(data.get(0)); Assert.true(friend1Obj.has("id")); Assert.true(friend1Obj.has("name")); JSONObject friend2Obj = friends.getJSONObject(data.get(1)); Assert.true(friend2Obj.has("id")); Assert.true(friend2Obj.has("name")); if ("Carter Page".equals(friend1Obj.getString("name"))) { Assert.assertEquals(123, friend1Obj.getInt("id")); Assert.assertEquals("Corby Page", friend2Obj.getString("name")); Assert.assertEquals(456, friend2Obj.getInt("id")); } else if ("Corby Page".equals(friend1Obj.getString("name"))) { Assert.assertEquals(456, friend1Obj.getInt("id")); Assert.assertEquals("Carter Page", friend2Obj.getString("name")); Assert.assertEquals(123, friend2Obj.getInt("id")); } else { Assert.fail("Expected either Carter or Corby, Got: " + friend1Obj.getString("name")); }
Error Messages
We tried to make error messages easy to understand. This is really important, since it gets hard for the eye to pick out the difference, particularly in long JSON strings. For example:
String expected = "{id:1,name:\"Joe\",friends:[{id:2,name:\"Pat\",pets:[\"dog\"]},{id:3,name:\"Sue\",pets:[\"bird\",\"fish\"]}],pets:[]}";
String actual = "{id:1,name:\"Joe\",friends:[{id:2,name:\"Pat\",pets:[\"dog\"]},{id:3,name:\"Sue\",pets:[\"cat\",\"fish\"]}],pets:[]}"
JSONAssert.assertEquals(expected, actual, false);
returns the following:
friends[id=3].pets[]: Expected bird, but not found ; friends[id=3].pets[]: Contains cat, but not expected
Which tells you that the pets array under the friend where id=3 was supposed to contain "bird", but had "cat" instead. (Maybe the cat ate the bird?)
QuickStart
To use, download the JAR or add the following to your project's pom.xml:
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
Write tests like this:
JSONAssert.assertEquals(expectedJSONString, actualJSON, strictMode);
Who uses JSONassert?
- yoga - A relational REST framework
- hamcrest-json - Hamcrest matchers for comparing JSON documents
- Mule ESB
- GroupDocs
- Shazam
- Thucydides
org.json
This implementation uses a clean-room implementation of the org.json library implemented for the Android system, released under the Apache 2.0 license. See com.vaadin.external.google:android-json That jar does not include the org.json.JSONString interface, so a new implementation of that interface is added to this source.
Resources
*Note that all licence references and agreements mentioned in the JSONAssert README section above
are relevant to that project's source code only.