{"id":16113187,"url":"https://github.com/joshka/junit-json-params","last_synced_at":"2025-04-07T07:18:27.332Z","repository":{"id":48978851,"uuid":"120233954","full_name":"joshka/junit-json-params","owner":"joshka","description":"JUnit 5 JSON Parameterized Tests library","archived":false,"fork":false,"pushed_at":"2025-03-03T13:26:10.000Z","size":883,"stargazers_count":57,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T06:06:41.525Z","etag":null,"topics":["java","json","jsonp","junit-json","junit5","parameterized-tests","unit-testing"],"latest_commit_sha":null,"homepage":"http://www.joshka.net/junit-json-params","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshka.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2018-02-04T23:42:36.000Z","updated_at":"2025-03-07T10:32:50.000Z","dependencies_parsed_at":"2024-03-12T10:51:22.258Z","dependency_job_id":"d07bcd12-59aa-4c5c-9624-fea37e803738","html_url":"https://github.com/joshka/junit-json-params","commit_stats":{"total_commits":260,"total_committers":5,"mean_commits":52.0,"dds":0.55,"last_synced_commit":"7985b5343ddd4dbef624fa6db60e303e405a74b9"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshka%2Fjunit-json-params","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshka%2Fjunit-json-params/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshka%2Fjunit-json-params/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshka%2Fjunit-json-params/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshka","download_url":"https://codeload.github.com/joshka/junit-json-params/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608160,"owners_count":20965953,"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","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","json","jsonp","junit-json","junit5","parameterized-tests","unit-testing"],"created_at":"2024-10-09T20:10:31.802Z","updated_at":"2025-04-07T07:18:27.301Z","avatar_url":"https://github.com/joshka.png","language":"Java","funding_links":[],"categories":["测试"],"sub_categories":[],"readme":"# junit-json-params\n\nA [Junit 5](http://junit.org/junit5/) library to provide annotations that load\ndata from JSON Strings or files in parameterized tests.\n\n## Library status\n\n\u003e [!CAUTION]\n\u003e\n\u003e I haven't actively written any Java in about 2 years, so this is in the barely maintained bucket\n\u003e Please feel free to fork this it and release under a different namespace. I'm happy to slap a link\n\u003e to a maintained fork on this repo to point at the new code, but I don't have the inclination to\n\u003e maintain it myself.\n\n## Project Info\n\n[![Maven Central Version](https://img.shields.io/maven-central/v/net.joshka/junit-json-params?style=for-the-badge)](https://central.sonatype.com/artifact/net.joshka/junit-json-params)\n[![Javadocs](https://javadoc.io/badge/net.joshka/junit-json-params.svg?style=for-the-badge)](https://javadoc.io/doc/net.joshka/junit-json-params)\n[![GitHub License](https://img.shields.io/github/license/joshka/junit-json-params?style=for-the-badge)](./LICENSE.txt)  \\\n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/joshka/junit-json-params/gradle.yml?style=for-the-badge)](https://github.com/joshka/junit-json-params/actions/workflows/gradle.yml)\n[![Sonar Quality Gate](https://img.shields.io/sonar/quality_gate/joshka_junit-json-params?server=https%3A%2F%2Fsonarcloud.io\u0026style=for-the-badge)](https://sonarcloud.io/project/overview?id=joshka_junit-json-params)\n[![Sonar Coverage](https://img.shields.io/sonar/coverage/joshka_junit-json-params?server=https%3A%2F%2Fsonarcloud.io\u0026style=for-the-badge)](https://sonarcloud.io/component_measures?id=joshka_junit-json-params\u0026metric=coverage\u0026view=list)\n\n## Installation\n\n### Apache Maven\n\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003enet.joshka\u003c/groupId\u003e\n        \u003cartifactId\u003ejunit-json-params\u003c/artifactId\u003e\n        \u003cversion\u003e5.10.2-r0\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.eclipse.parsson\u003c/groupId\u003e\n        \u003cartifactId\u003eparsson\u003c/artifactId\u003e\n        \u003cversion\u003e1.1.1\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n### Gradle\n\n```groovy\ntestImplementation 'net.joshka:junit-json-params:5.10.2-r0'\ntestImplementation 'org.eclipse.parsson:parsson:1.1.1'\n```\n\n## Examples\n\n### `@JsonSource`\n\n`@JsonSource` allows you to specify argument lists as JSON strings.\n\nSee [`JsonArgumentsProviderTest`](https://github.com/joshka/junit-json-params/blob/master/src/test/java/net/joshka/junit/json/params/JsonArgumentsProviderTest.java)\n\n```java\nimport net.joshka.junit.json.params.JsonSource;\n\nclass JsonArgumentsProviderTest {\n    /**\n     * When passed \u003ccode\u003e{\"key\":\"value\"}\u003c/code\u003e, is executed a single time\n     * @param object the parsed JsonObject\n     */\n    @ParameterizedTest\n    @JsonSource(\"{\\\"key\\\":\\\"value\\\"}\")\n    @DisplayName(\"provides a single object\")\n    void singleObject(JsonObject object) {\n        assertThat(object.getString(\"key\")).isEqualTo(\"value\");\n    }\n\n    /**\n     * When passed \u003ccode\u003e[{\"key\":\"value1\"},{\"key\",\"value2\"}]\u003c/code\u003e, is\n     * executed once per element of the array\n     * @param object the parsed JsonObject array element\n     */\n    @ParameterizedTest\n    @JsonSource(\"[{\\\"key\\\":\\\"value1\\\"},{\\\"key\\\":\\\"value2\\\"}]\")\n    @DisplayName(\"provides an array of objects\")\n    void arrayOfObjects(JsonObject object) {\n        assertThat(object.getString(\"key\")).startsWith(\"value\");\n    }\n\n    /**\n     * When passed \u003ccode\u003e[1, 2]\u003c/code\u003e, is executed once per array element\n     * @param number the parsed JsonNumber for each array element\n     */\n    @ParameterizedTest\n    @JsonSource(\"[1,2]\")\n    @DisplayName(\"provides an array of numbers\")\n    void arrayOfNumbers(JsonNumber number) {\n        assertThat(number.intValue()).isPositive();\n    }\n\n    /**\n     * When passed \u003ccode\u003e[\"value1\",\"value2\"]\u003c/code\u003e, is executed once per array\n     * element\n     * @param string the parsed JsonString for each array element\n     */\n    @ParameterizedTest\n    @JsonSource(\"[\\\"value1\\\",\\\"value2\\\"]\")\n    @DisplayName(\"provides an array of strings\")\n    void arrayOfStrings(JsonString string) {\n        assertThat(string.getString()).startsWith(\"value\");\n    }\n\n    /**\n     * When passed \u003ccode\u003e{'key':'value'}\u003c/code\u003e, is executed a single time.\n     * This simplifies writing inline JSON strings\n     * @param object the parsed JsonObject\n     */\n    @ParameterizedTest\n    @JsonSource(\"{'key':'value'}\")\n    @DisplayName(\"handles simplified json\")\n    void simplifiedJson(JsonObject object) {\n        assertThat(object.getString(\"key\")).isEqualTo(\"value\");\n    }\n}\n```\n\n### `@JsonFileSource`\n\n`@JsonFileSource` lets you use JSON files from the classpath. It supports\nsingle objects and arrays of objects and JSON primitives (numbers and strings).\n\nSee [`JsonFileArgumentsProviderTest`](https://github.com/joshka/junit-json-params/blob/master/src/test/java/net/joshka/junit/json/params/JsonFileArgumentsProviderTest.java)\n\n```java\nimport net.joshka.junit.json.params.JsonFileSource;\n\nclass JsonFileArgumentsProviderTest {\n    /**\n     * When passed \u003ccode\u003e{\"key\":\"value\"}\u003c/code\u003e, is executed a single time\n     * @param object the parsed JsonObject\n     */\n    @ParameterizedTest\n    @JsonFileSource(resources = \"/single-object.json\")\n    @DisplayName(\"provides a single object\")\n    void singleObject(JsonObject object) {\n        assertThat(object.getString(\"key\")).isEqualTo(\"value\");\n    }\n\n    /**\n     * When passed \u003ccode\u003e[{\"key\":\"value1\"},{\"key\",\"value2\"}]\u003c/code\u003e, is\n     * executed once per element of the array\n     * @param object the parsed JsonObject array element\n     */\n    @ParameterizedTest\n    @JsonFileSource(resources = \"/array-of-objects.json\")\n    @DisplayName(\"provides an array of objects\")\n    void arrayOfObjects(JsonObject object) {\n        assertThat(object.getString(\"key\")).startsWith(\"value\");\n    }\n\n    /**\n     * When passed \u003ccode\u003e[1, 2]\u003c/code\u003e, is executed once per array element\n     * @param number the parsed JsonNumber for each array element\n     */\n    @ParameterizedTest\n    @JsonFileSource(resources = \"/array-of-numbers.json\")\n    @DisplayName(\"provides an array of numbers\")\n    void arrayOfNumbers(JsonNumber number) {\n        assertThat(number.intValue()).isPositive();\n    }\n\n    /**\n     * When passed \u003ccode\u003e[\"value1\",\"value2\"]\u003c/code\u003e, is executed once per array\n     * element\n     * @param string the parsed JsonString for each array element\n     */\n    @ParameterizedTest\n    @JsonFileSource(resources = \"/array-of-strings.json\")\n    @DisplayName(\"provides an array of strings\")\n    void arrayOfStrings(JsonString string) {\n        assertThat(string.getString()).startsWith(\"value\");\n    }\n}\n```\n\n## License\n\nCopyright ©️ 2019-2024 Joshua McKinney\n\nCode is under the [Apache License 2.0](LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshka%2Fjunit-json-params","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshka%2Fjunit-json-params","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshka%2Fjunit-json-params/lists"}