在Maven测试之前和之后如何运行

时间:2019-08-08 11:26:22

标签: maven junit

mvn test

我希望在使用maven test执行所有测试用例之前初始化某些资源,并在执行所有测试用例之后销毁它们。

我研究了jUnit @BeforeClass @AfterClass @Before @After ,但是没有一个其中有帮助。

我试图使用Maven生命周期阶段,即如下所示的集成前测试,但即使在这种情况下,预期的测试用例(TestPostgresqlEmbedded)也不会首先执行。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>${maven.surefire.plugin.version}</version>
  <executions>
    <execution>
        <id>test-init</id>
        <configuration>
          <runOrder>alphabetical</runOrder>
          <includes>
            <include>**/TestPostgresqlEmbedded.java</include>
          </includes>
        </configuration>
        <phase>pre-integration-test</phase>
    </execution>
    <execution>
        <id>test-all</id>
        <configuration>
          <runOrder>alphabetical</runOrder>
        </configuration>
    </execution>
  </executions>
</plugin>

我该如何实现?

1 个答案:

答案 0 :(得分:0)

integration-test阶段用于数据库测试。然后,您有pre-integration-test来设置数据库资源,并有post-integration-test来破坏它们。

相关问题