{"id":20532389,"url":"https://github.com/unitvectory-labs/jsonparamunit","last_synced_at":"2025-08-17T14:06:02.449Z","repository":{"id":225568279,"uuid":"765947298","full_name":"UnitVectorY-Labs/jsonparamunit","owner":"UnitVectorY-Labs","description":"Library for creating parameterized JUnit 5 tests based on JSON files.","archived":false,"fork":false,"pushed_at":"2025-08-16T13:14:26.000Z","size":317,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-16T13:47:42.495Z","etag":null,"topics":["java-17","json","junit5","mavencentral"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UnitVectorY-Labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-01T23:53:59.000Z","updated_at":"2025-08-16T13:14:28.000Z","dependencies_parsed_at":"2025-04-26T12:25:36.509Z","dependency_job_id":"1b8f4506-5ba7-4c45-8d6c-98af3cda7b3f","html_url":"https://github.com/UnitVectorY-Labs/jsonparamunit","commit_stats":null,"previous_names":["unitvectory-labs/jsonparamunit"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/UnitVectorY-Labs/jsonparamunit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnitVectorY-Labs%2Fjsonparamunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnitVectorY-Labs%2Fjsonparamunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnitVectorY-Labs%2Fjsonparamunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnitVectorY-Labs%2Fjsonparamunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UnitVectorY-Labs","download_url":"https://codeload.github.com/UnitVectorY-Labs/jsonparamunit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnitVectorY-Labs%2Fjsonparamunit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270728387,"owners_count":24635207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java-17","json","junit5","mavencentral"],"created_at":"2024-11-16T00:14:35.609Z","updated_at":"2025-08-17T14:06:02.439Z","avatar_url":"https://github.com/UnitVectorY-Labs.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub release](https://img.shields.io/github/release/UnitVectorY-Labs/jsonparamunit.svg)](https://github.com/UnitVectorY-Labs/jsonparamunit/releases/latest) [![License](https://img.shields.io/badge/License-EPL%202.0-blue.svg)](https://www.eclipse.org/legal/epl-v20.html) [![Active](https://img.shields.io/badge/Status-Active-green)](https://guide.unitvectorylabs.com/bestpractices/status/#active) [![Maven Central](https://img.shields.io/maven-central/v/com.unitvectory/jsonparamunit)](https://central.sonatype.com/artifact/com.unitvectory/jsonparamunit) [![javadoc](https://javadoc.io/badge2/com.unitvectory/jsonparamunit/javadoc.svg)](https://javadoc.io/doc/com.unitvectory/jsonparamunit) [![codecov](https://codecov.io/gh/UnitVectorY-Labs/jsonparamunit/graph/badge.svg?token=EAJEIFCXYU)](https://codecov.io/gh/UnitVectorY-Labs/jsonparamunit)\n\n# jsonparamunit\n\nLibrary for creating parameterized JUnit 5 tests based on JSON files.\n\n## Purpose\n\nThe core objective of this library is to streamline the way developers approach unit testing in Java through the use of data driven test cases. By leveraging JSON for defining test parameters, including inputs and expected outputs, `jsonparamunit` aims to simplify the process of creating and maintaining test cases.\n\nThis approach allows developers to focus on the logic and behavior of the code under test, rather than the mechanics of test case setup. When combined with [fileparamunit](https://github.com/UnitVectorY-Labs/fileparamunit) the test cases are defined as JSON with a single Java class calling the method to test.\n\nDesigned for ease of integration into existing Java 17+ and JUnit 5 projects, this library aims to increase code coverage by shifting code from\n\n## Getting Started\n\nThis library requires Java 17 and JUnit 5 and is available in the Maven Central Repository:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.unitvectory\u003c/groupId\u003e\n    \u003cartifactId\u003ejsonparamunit\u003c/artifactId\u003e\n    \u003cversion\u003e0.0.7\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\nThe goal of this library is to utilize JSON as a means of defining test cases. Instead of writing Java code, JSON files are used with the following structure:\n\n```json\n{\n  \"input\": {\n    \"value\": \"1234567890\"\n  },\n  \"context\": \"optionalContext\",\n  \"output\": {\n    \"value\": \"0987654321\"\n  }\n}\n```\n\n- The `input` is an arbitrary JSON object representing the input of the test case\n- The `context` is an optional JSON string that can be used as additional context in processing that is not part of the input\n- The `output` is an arbitrary JSON object representing the expected output of the test case; the output will be compared to the actual output of the test case using [JSON Assert](https://github.com/skyscreamer/JSONassert) acting as the core of each test case\n\nThere are 3 classes that can be used to create the test cases through extension that operate on the JSON Object at different levels of parsing:\n\n`JsonStringParamUnit`: Input is passed a String containing the encoded JSON and output expects a String with the output JSON encoded.\n\n```java\nString process(String input, String context)\n```\n\n`JsonNodeParamUnit`: Input is passed as a Jackson JsonNode and output is expected as a JsonNode allowing for flexible handling of the input and output.\n\n```java\nJsonNode process(JsonNode input, String context)\n```\n\n`JsonClassParamUnit`: Input and output are both handled as POJOs utilziing Jackson to handle the serliziation and deserialization from the input and output. A complete example follows giving the following example class being used as both the input and output.\n\n```java\npackage example;\n\nimport lombok.AllArgsConstructor;\nimport lombok.Builder;\nimport lombok.Data;\nimport lombok.NoArgsConstructor;\n\n@Data\n@Builder\n@NoArgsConstructor\n@AllArgsConstructor\npublic class TestObject {\n\n    private String value;\n}\n```\n\nThe example shown here is using reversing a string as the example, but in practice the input and output are expected to be more complex objects exercising the logic of the code under test.\n\nThis example also uses [fileparamunit](https://github.com/UnitVectorY-Labs/fileparamunit) to iterate through all of the JSON files contained in the `/strings` directory under the test resources allowing additional test cases to be created without modifying the Java code.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.unitvectory\u003c/groupId\u003e\n    \u003cartifactId\u003efileparamunit\u003c/artifactId\u003e\n    \u003cversion\u003e0.0.5\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nThe actual execution of a test is performed by calling the `run` method passing in the path to the JSON file with the test case.\n\n```java\npackage example;\n\nimport org.junit.jupiter.params.ParameterizedTest;\nimport com.fasterxml.jackson.databind.DeserializationFeature;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.unitvectory.fileparamunit.ListFileSource;\nimport com.unitvectory.jsonparamunit.JsonClassParamUnit;\n\npublic class ReverseStringTest extends JsonClassParamUnit\u003cTestObject, TestObject\u003e {\n\n    @ParameterizedTest\n    @ListFileSource(resources = \"/strings/\", fileExtension = \".json\", recurse = false)\n    public void testIt(String file) {\n        // Utilize jsonparamunit to have a test case for each JSON file\n        run(file);\n    }\n\n    protected ReverseStringTest() {\n        super(InputString.class, JsonParamUnitConfig.builder().build());\n    }\n\n    @Override\n    public TestObject process(TestObject input, String context) {\n        // This represents the functionality you want to test, in this example the functionality is\n        // just reversing a string but in real life this would be a complex operation to unit test\n        String reversedString = new StringBuilder(input.getValue()).reverse().toString();\n        return TestObject.builder().value(reversedString).build();\n    }\n}\n```\n\nThe `JsonParamUnitTest` can be provided as a constructor parameter to be able to customize the behavior of the test case.\n\n- The Jackson ObjectMapper can be provided using the `mapper` parameter.\n- The JSON Assert behavior defaults to strict which is highly recommended but can be changed using the `strictOutput` parameter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funitvectory-labs%2Fjsonparamunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funitvectory-labs%2Fjsonparamunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funitvectory-labs%2Fjsonparamunit/lists"}