如何在不模拟 Doclet API 的情况下测试 Java 9+ doclet?

How to test Java 9+ doclet without mocking Doclet API?

我使用 Java 9+ 编写了一个 Doclet。我想在不模拟 Doclet API 的情况下使用 JUnit 框架对其进行测试。有什么好的方法吗?

当您知道要使用什么时,答案很简单。 这是一个可以在 JUnit 测试中使用的手动调用示例。

DocumentationTool systemDocumentationTool = ToolProvider.getSystemDocumentationTool();
        String[] args = new String[] {
          "-sourcepath",
          "./src/test/java",
          "-subpackages",
          "<whatever-package-in-test-sources>",
          "<whatever-package-in-test-sources>",
          "-d",
          "whatever not used just to show compatibility",
          "-author",
          "whatever not used just to show compatibility",
          "-doctitle",
          "whatever not used just to show compatibility",
          "-windowtitle",
          "whatever not used just to show compatibility",
          "-classdir",
          BUILD_PROPERTY_FILE_LOCATION
        };
        DocumentationTool.DocumentationTask task = systemDocumentationTool.getTask(null, null, null,
          <MyDocletClass>.class, Arrays.asList(args), null);

        task.call();
        // Your checks after invocation