1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00
A reference implementation of a JSON package in Java.
Find a file
2015-05-24 23:36:48 -05:00
CDLTest.java 98% coverage 2015-04-23 21:41:46 -05:00
CookieListTest.java 96.5% coverage 2015-04-27 14:56:01 -05:00
CookieTest.java 98.9% coverage 2015-04-26 17:46:52 -05:00
HTTPTest.java 98.7% coverage 2015-04-04 14:01:29 -05:00
JSONArrayTest.java 95.9% coverage 2015-04-14 01:12:08 -05:00
JSONMLTest.java test JSONML.toString(JSONArray) 2015-04-19 17:11:51 -05:00
JSONObjectTest.java fix so numeric behavior is documented but tests succeed 2015-05-24 23:36:48 -05:00
JSONStringerTest.java 93.8% coverage 2015-04-04 14:01:52 -05:00
JunitTestSuite.java added JSONArrayTest 2015-04-23 21:47:15 -05:00
LICENSE.txt Add LICENSE file via addalicense.com 2015-03-16 12:06:41 -05:00
PropertyTest.java PropertTest.java coverage 94.8% 2015-03-19 17:30:44 -05:00
README.md Update README.md 2015-05-09 15:26:15 -05:00
StringsResourceBundle.java in progress 2015-04-06 19:01:54 -05:00
TestRunner.java test suite and cookie test 2015-03-18 22:39:54 -05:00
Util.java improved object comparison 2015-04-23 21:42:04 -05:00
XMLTest.java coverage XMLTest 81.2% / XMLTokener 82.2% 2015-03-26 22:58:11 -05:00

JSON-Java-unit-test

Unit tests to validate the JSON-Java GitHub project code
https://github.com/douglascrockford/JSON-java

These tests are a work in progress. Help from interested developers is welcome.
More coverage is needed, but more importantly, improvements to test quality is needed.

You will need the following libraries for testing: Test harness: http://junit.org
Coverage: http://www.eclemma.org/
Mockery: https://github.com/mockito/mockito

Eclipse is the recommended development environment. Run individual tests or JunitTestSuite using EclEmma Coverage, or execute the TestRunner application directly.

Test filenames should consist of the name of the module being tested, with the suffix "Test". For example, Cookie.java is tested by CookieTest.java. When adding a new unit test, don't forget to update JunitTestSuite.java.

The fundamental issues with JSON-Java testing are:

  • JSONObjects are unordered, making simple string comparison ineffective.
  • Comparisons via equals() is not currently supported. Neither JSONArray nor JSONObject overrride hashCode() or equals(), so comparison defaults to the Object equals(), which is not useful.
  • Access to the JSONArray and JSONObject internal containers for comparison is not currently available.

General issues with unit testing are:

  • Just writing tests to make coverage goals tends to result in poor tests.
  • Unit tests are a form of documentation - how a given method actually works is demonstrated by the test. So for a code reviewer or future developer looking at code a good test helps explain how a function is supposed to work according to the original author. This can be difficult if you are not the original developer.
  • It is difficult to evaluate unit tests in a vacuum. You also need to see the code being tested to understand if a test is good.
  • Without unit tests it is hard to feel confident about the quality of the code, especially when fixing bugs or refactoring. Good tests prevents regressions and keeps the intent of the code correct.
  • If you have unit test results along with pull requests, the reviewer has an easier time understanding your code and determining if the it works as intended.

When you start working on a test, add the empty file to the repository and update the readme, so that others will know that test is taken.

A unit test has the following stages:

Test phase Description
No test No test specifically for this class has been written, or the class contains no executable code.
In progress Unit tests have been started for this class.
Coverage > 90% Initial goal of 90% coverage has been reached. Test quality may be questionable
Reasonable test cases 90% coverage. Functionality and behavior has been confirmed
Checked against previous unit tests Historical unit tests have been checked in case something important was missed
Completed The unit test is completed
Test file name Coverage Comments
Total coverage 88.9%
CDL.java 98% Reasonable test cases.
Cookie.java 98.9% Reasonable test cases.
CookieList.java 96.5% Reasonable test cases.
HTTP.java 98.7% Coverage > 90%
HTTPTokener.java 93.2% No test
JSONArray.java 95.9% Coverage > 90%
JSONException.java 26.7% No test
JSONML.java 83.2% In progress
JSONObject 90.9% Coverage > 90%
JSONObject.Null 87.5% No test
JSONString.java No test
JSONStringer.java 93.8% Coverage > 90%
JSONTokener.java 72.1% In progress
JSONWriter.java 88.9% No test
Property.java 94.8% Coverage > 90%
XML.java 85.1% In progress
XMLTokener.java 82.7% No test
Files used in test
JunitTestSuite.java
StringsResourceBundle.java
TestRunner.java
Util.java