Assert JSON

JSONassert is a project to “Write JSON unit tests in less code. Great for testing REST interfaces.” The following is maven dependency of JSONassert:

<dependency>
 <groupId>org.skyscreamer</groupId>
 <artifactId>jsonassert</artifactId>
 <version>1.3.0</version>
</dependency>

To test whether 2 JSON objects are same or not, do the following:

JSONAssert.assertEquals(expectedJson, actualJson, JSONCompareMode.NON_EXTENSIBLE);

NON_EXTENSIBLE is the most commonly used compare mode of 4. You can check javadoc to find out how they function.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s