在 Idea 中执行时在 JUnit 测试中生成的文件,但在通过 mvn 测试执行时不会生成

Files generated in JUnit Tests while executed in Idea but not when executed via mvn test

我有一个 JUnit 测试,它从 springfox swagger 端点生成一些 asciidoc 文件。如果我从Idea执行测试会生成这些文件,但如果我通过mvn test执行测试则不会生成这些文件。有办法解决这个问题吗?

  @Test
  public void convertSwaggerToAsciiDoc() throws Exception {
      this.mockMvc.perform(get("/v2/api-docs")
              .accept(MediaType.APPLICATION_JSON))
              .andDo(Swagger2MarkupResultHandler.outputDirectory("src/docs/asciidoc/generated")
                         .build())
              .andExpect(status().isOk());
  }

应该通过 maven-asciidoctor-plugin 使用 asciidoctor 进一步处理生成的文件:

      <plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>1.5.3</version>
    <configuration>
      <sourceDirectory>src/docs/asciidoc/generated</sourceDirectory>
      <outputDirectory>src/main/resources/public/doc/</outputDirectory>
      <sourceDocumentName>index.adoc</sourceDocumentName>
      <backend>html5</backend>
      <sourceHighlighter>coderay</sourceHighlighter>
      <attributes>
        <toc>left</toc>
      </attributes>
      <headerFooter>true</headerFooter>
    </configuration>
    <executions>
      <execution>
        <id>output-html</id>
        <phase>package</phase>
        <goals>
          <goal>process-asciidoc</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

但是如果我执行 'mvn package'.

文件不会更新

IntelliJ 运行它在 src/test/java 文件夹中找到的所有测试,只查看注释。

maven 测试运行程序仅检查文件名以 Test 结尾的文件。因此,如果测试名称 class 以 Test 结尾,请检查它(唉,您没有显示整个测试 class 定义)。