Unit tests to validate the JSON-Java GitHub project code
Gradle and Eclipse is the recommended build tool and IDE.
Run individual tests or JunitTestSuite using EclEmma Coverage, or execute the TestRunner application directly.
The following libraries are required:
To build from the command line using gradle:
Until the unit tests are merged into the JSON-Java project, the code has to be wired by hand.
# In an empty directory of your choice, clone JSON-Java-unit-test:
git clone https://github.com/stleary/JSON-Java-unit-test.git .
# Create a directory structure for the JSON-Java code
# Windows 10 version mkdir src\main\java\org\json # *nix version mkdir -p src/main/java/org/json
# clone JSON-Java
#Windows version git clone https://github.com/stleary/JSON-Java.git src\main\java\org\json #*Nix version git clone https://github.com/stleary/JSON-Java.git src/main/java/org/json
# Build, then execute the unit tests and code coverage
gradle clean build test jacocoTestReport
# Eclipse setup requires the Gradle IDE plug-in
# I use Gradle IDE 22.214.171.124503050952-RELEASE org.springsource.ide.eclipse.gradle.feature.feature.group Pivotal Software, Inc.
# From the Eclipse IDE:
File > Import > Gradle project > (navigate to your directory) > Build Model > (Select your directory) > Finish (It is not necessary to run "gradle eclipse" on the project, from the command line)
Unit test results will be in build\reports\tests\index.html
Code coverage will be in build\reports\jacoco\html\index.html
To create an Eclipse project, you will need the Eclipse Gradle plug-in, available from the Eclipse Marketplace. I am currently using Gradle IDE 126.96.36.199503050952-RELEASE
Select File > Import > Gradle > Gradle project
Browse to the directory where you cloned JSON-Java-unit-test
Select Build model
Select built project
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:
General issues with unit testing are:
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.
Caveats: JSON-Java is Java 1.6-compatible, but JSON-Java-unit-tests requires Java 1.8. If you see this error when building JSON-Java-unit-test, make sure you have 1.8 installed, on your path, and set in JAVA_HOME:
Execution failed for task ':compileJava'. > invalid flag: -parameters
|Resource files used in test|