Creating temporary database that works across maven test phases?

后端 未结 2 1351
走了就别回头了
走了就别回头了 2020-11-30 14:09

I\'ve joined a project that has a lot of files with SQL statements for creating a database that is used for integration testing.

I\'m wondering how I can use these f

相关标签:
2条回答
  • 2020-11-30 14:47

    For this case I have created the derby-maven-plugin. It's available from Maven Central, so you don't need to add any extra repositories or anything.

    You could use it like this:

        <project ...>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.carlspring.maven</groupId>
                        <artifactId>derby-maven-plugin</artifactId>
                        <version>1.8</version>
                        <configuration>
                            <basedir>${project.build.directory}/derby</basedir>
                            <port>1527</port>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-derby</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-derby</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </project>
    

    For more info you can also check the USAGE.

    0 讨论(0)
  • 2020-11-30 15:02
    1. Why not create an on-disk H2 database, and have each test access it? So long as the tests don't run in parallel or interact with each other, you don't need a server.

    2. Even more so: just create memory databases in @Before and delete them in @After. Are you sure that's too slow?

    3. In pre-integration-test, you could launch an H2 (or derby) server, and shut it down in post-integration-test.

    4. You can write a maven plugin that uses session state to keep track of an embedded database service, but that's much the same as (3).

    0 讨论(0)
提交回复
热议问题