How to use Oracle as an embedded database to run unit tests in maven?

I have an application for which the prod / test / qa database is Oracle only. In addition, I suspect that SQL queries are specific to Oracle. And unfortunately, this application takes second place without unit tests.

As a result, I would like to implement for unit tests, especially with respect to the search component (which obviously performs many Oracle operations, including creating a table).

Usually, when I want to run tests, I run a built-in database (e.g. HSQL), run my tests in that database and let it disappear when my tests finish.

Due to my lack of confidence in the standardization level of this application, I would prefer to run tests in an Oracle database. As a result, I would like to start the oracle database when my tests start, fill it with some test datan and stop it at the end of the test. How can I do this in a maven context?

+5
source share
2 answers

I understand that you want Oracle, but you can also try with h2 using the oracle mode flag

jdbc:h2:~/test;MODE=Oracle 

I have the same need for most of my projects, and this is the closest to Oracle I have found. You can define aliases for several missing functions.

+2
source

You can use exec-maven-plugin to run any application during the Maven life cycle, including a full Oracle instance. However, you still need to install it on the builder, etc., which complicates the decision quite a bit.

So what we did in another project:

  • Define the unique assembly name as the Maven property (by default for the username for local builds, let CI provide this via -D , for example, on Bamboo you can include the plan plan key and number)
  • Connecting to a shared instance of Oracle in our infrastructure
  • Create a new schema based on a specific assembly name
  • Update the new empty circuit with DDL (we use Flyway in the production process, so this part is simple)
  • Run Integration Tests
  • Post-integration output scheme (since assemblies can be stopped manually or hung, you still need to have some automatic database cleanup for legacy schemes)

You can use sql-maven-plugin to execute SQL scripts. Or flyway-maven-plugin , if you use Flyway.

+2
source

All Articles