Starting an H2 Database Server from Maven?

后端 未结 9 1680
不思量自难忘°
不思量自难忘° 2021-01-30 07:09

Suppose I want to create and use an H2 database for my integration tests.

Maven has a command to run tests: mvn test.

Is there a way to tell maven t

9条回答
  •  后悔当初
    2021-01-30 07:31

    you can create 2 small classes with main methods that start and stop the database. the idea is to run the StartServer class before the integration tests are run and then class StopServer after the tests have run.

    you should do the same for your DB server as described somewhere in this document (description is for starting and stopping Jetty in integration tests)

    in your pom.xml you should define the maven-exec-plugin to run the exec:java goal and create 2 executions (1 for calling StartServer and 1 for StopServer):

    
      org.codehaus.mojo
      exec-maven-plugin
      1.1.1
      
        
          
          start
          pre-integration-test
          
            java
          
          
            com.foo.StartServer
          
         
         
          
          stop
          post-integration-test
          
            java
          
          
            com.foo.StopServer
          
         
       
     
    

    hope that's what you want

提交回复
热议问题