1

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

4

1 回答 1

2

当您知道要使用什么时,答案很简单。这是可用于 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

于 2019-04-26T17:35:47.023 回答