{"id":24316479,"url":"https://github.com/jferard/doctest","last_synced_at":"2026-05-28T06:05:09.467Z","repository":{"id":170593564,"uuid":"153839157","full_name":"jferard/doctest","owner":"jferard","description":"A Maven \"DocTest for Java\" plugin proof of concept","archived":false,"fork":false,"pushed_at":"2023-08-27T10:07:33.000Z","size":27,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T12:59:29.874Z","etag":null,"topics":["doctest","java","maven-plugin","proof-of-concept","testing-tools"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jferard.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}},"created_at":"2018-10-19T20:37:52.000Z","updated_at":"2023-08-27T10:07:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7544d45-a200-4838-9898-99a8d1ce61ad","html_url":"https://github.com/jferard/doctest","commit_stats":null,"previous_names":["jferard/doctest"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferard%2Fdoctest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferard%2Fdoctest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferard%2Fdoctest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferard%2Fdoctest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jferard","download_url":"https://codeload.github.com/jferard/doctest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242855643,"owners_count":20196359,"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":["doctest","java","maven-plugin","proof-of-concept","testing-tools"],"created_at":"2025-01-17T12:56:39.762Z","updated_at":"2025-12-16T05:30:56.899Z","avatar_url":"https://github.com/jferard.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaDocTest\n\nCopyright (C) J. Férard 2018\n\nA \"Maven DocTest (see https://docs.python.org/3.7/library/doctest.html) for Java\" plugin **proof of concept**.\n\n**Not designed to be used in exploitation.**\n\n**Uses the old com.sun.javadoc API**\n\n## Installation\n\n    cd doctest\n    mvn clean install\n\n## Quick Test\n\n    cd DocTestExample # or any project of your own with doctests.\n    mvn clean com.github.jferard:doctest-maven-plugin:0.0.1-SNAPSHOT:doctest test\n\nOutput:\n\n    ...\n    -------------------------------------------------------\n     T E S T S\n    -------------------------------------------------------\n    Running com.github.jferard.doctest.CalculatorTest\n    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec\n\n    Results :\n\n    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0\n\n## POM configuration\nTo execute automatically the plugin:\n\n    \u003cplugins\u003e\n        ...\n        \u003cplugin\u003e\n            \u003cgroupId\u003ecom.github.jferard\u003c/groupId\u003e\n            \u003cartifactId\u003edoctest-maven-plugin\u003c/artifactId\u003e\n            \u003cversion\u003e0.0.1-SNAPSHOT\u003c/version\u003e\n            \u003cexecutions\u003e\n                \u003cexecution\u003e\n                    \u003cid\u003edoctest\u003c/id\u003e\n                    \u003cphase\u003egenerate-test-sources\u003c/phase\u003e\n                    \u003cgoals\u003e\n                        \u003cgoal\u003edoctest\u003c/goal\u003e\n                    \u003c/goals\u003e\n                \u003c/execution\u003e\n            \u003c/executions\u003e\n        \u003c/plugin\u003e\n    \u003c/plugins\u003e\n\nNow, a:\n\n    mvn clean test\n\nWill generate and execute the test.\n\n*Note: I added an `example` profile with those lines to the POM of `DocTestExample`. You can check it using:*\n\n    mvn -P example clean test\n\n## How does it work ?\n\nThe `DocTest` plugin:\n* add a new test directory source for the generated test class files;\n* starts the Maven Javadoc Plugin a custom doclet that extracts the test from the javadoc and builds a test class.\n\nThe example class `Calculator` contains the following lines:\n\n    /**\n     * \u003cpre\u003e\n     * {@code\n     * /// setUp\n     * Calculator c = new Calculator(0);\n     * }\u003c/pre\u003e\n     *\n     * \u003cpre\u003e\n     * {@code\n     * /// imports: java.lang.Math\n     * /// 1\n     * Assert.assertEquals(-100, c.subtract(100), 0.01);\n     * Assert.assertEquals(100, c.negate(), 0.01);\n     * Assert.assertEquals(377, c.add(277), 0.01);\n     * Assert.assertEquals(Math.PI, c.divide(120), 0.01);\n     * }\n     * \u003c/pre\u003e\n     */\n    public class Calculator {\n\n        ...\n\n        /**\n         * \u003cpre\u003e{@code\n         * /// 2\n         * /// imports: java.util.Random\n         * Float f = new Random().nextFloat();\n         * Assert.assertEquals(f, c.add(f), 0.01);\n         * }\u003c/pre\u003e\n         *\n         * @param n\n         *            the term to add\n         * @return the new value\n         */\n        public float add(float n) {\n            this.value += n;\n            return this.value;\n        }\n    ...\n\n\nThe generated test class is:\n\n    package com.github.jferard.doctest;\n\n    import org.junit.*;\n    import java.lang.Math;\n    import java.util.Random;\n\n    public class CalculatorTest {\n        @Test\n        public void test2() {\n             Calculator c = new Calculator(0);\n             Float f = new Random().nextFloat();\n             Assert.assertEquals(f, c.add(f), 0.01);\n        }\n\n        @Test\n        public void test1() {\n             Calculator c = new Calculator(0);\n             Assert.assertEquals(-100, c.subtract(100), 0.01);\n             Assert.assertEquals(100, c.negate(), 0.01);\n             Assert.assertEquals(377, c.add(277), 0.01);\n             Assert.assertEquals(Math.PI, c.divide(120), 0.01);\n        }\n\n    }\n\n## POM\nTo use automatically Since the heart of the Java DocTest is a simple doclet, you can add those plugins to the pom:\n\n    \u003cbuild\u003e\n        \u003cplugins\u003e\n            ...\n            \u003cplugin\u003e\n                \u003cgroupId\u003ecom.github.jferard\u003c/groupId\u003e\n                \u003cartifactId\u003edoctest-maven-plugin\u003c/artifactId\u003e\n                \u003cversion\u003e0.0.1-SNAPSHOT\u003c/version\u003e\n                \u003cexecutions\u003e\n                    \u003cexecution\u003e\n                        \u003cid\u003edoctest\u003c/id\u003e\n                        \u003cphase\u003egenerate-test-sources\u003c/phase\u003e\n                        \u003cgoals\u003e\n                            \u003cgoal\u003edoctest\u003c/goal\u003e\n                        \u003c/goals\u003e\n                    \u003c/execution\u003e\n                \u003c/executions\u003e\n            \u003c/plugin\u003e\n        \u003c/plugins\u003e\n    \u003c/build\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjferard%2Fdoctest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjferard%2Fdoctest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjferard%2Fdoctest/lists"}