Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1100359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:52:06+00:00 2026-05-17T00:52:06+00:00

I have an application where many unit tests use a real connection to an

  • 0

I have an application where many “unit” tests use a real connection to an Oracle database during their execution.

As you can imagine, these tests take too much time to be executed, as they need to initialize some Spring contexts, and communicate to the Oracle instance. In addition to that, we have to manage complex mechanisms, such as transactions, in order to avoid database modifications after the test execution (even if we use usefull classes from Spring like AbstractAnnotationAwareTransactionalTests).

So my idea is to progressively replace this Oracle test instance by an in-memory database. I will use hsqldb or maybe better h2.

My question is to know what is the best approach to do that. My main concern is related to the construction of the in-memory database structure and insertion of reference data.

Of course, I can extract the database structure from Oracle, using some tools like SQL Developer or TOAD, and then modifying these scripts to adapt them to the hsqldb or h2 language. But I don’t think that’s the better approach.


In fact, I already did that on another project using hsqldb, but I have written manually all the scripts to create tables. Fortunately, I had only few tables to create. My main problem during this step was to “translate” the Oracle scripts used to create tables into the hsqldb language.

For example, a table created in Oracle using the following sql command:

CREATE TABLE FOOBAR (
    SOME_ID NUMBER,
    SOME_DATE DATE, -- Add primary key constraint
    SOME_STATUS NUMBER,
    SOME_FLAG NUMBER(1) DEFAULT 0 NOT NULL);

needed to be “translated” for hsqldb to:

CREATE TABLE FOOBAR (
    SOME_ID NUMERIC,
    SOME_DATE TIMESTAMP PRIMARY KEY,
    SOME_STATUS NUMERIC,
    SOME_FLAG INTEGER DEFAULT 0 NOT NULL);

In my current project, there are too many tables to do that manually…


So my questions:

  • What are the advices you can give me to achieve that?
  • Does h2 or hsqldb provide some tools to generate their scripts from an Oracle connection?

Technical information

Java 1.6, Spring 2.5, Oracle 10.g, Maven 2


Edit

Some information regarding my unit tests:

In the application where I used hsqldb, I had the following tests:
– Some “basic” unit tests, which have nothing to do with DB.
– For DAO testing, I used hsqldb to execute database manipulations, such as CRUD.
– Then, on the service layer, I used Mockito to mock my DAO objects, in order to focus on the service test and not the whole applications (i.e. service + dao + DB).

In my current application, we have the worst scenario: The DAO layer tests need an Oracle connection to be run. The services layer does not use (yet) any mock objects to simulate the DAO. So services tests also need an Oracle connection.

I am aware that mocks and in-memory database are two separates points, and I will address them as soon as possible. However, my first step is to try to remove the Oracle connection by an in-memory database, and then I will use my Mockito knowledges to enhance the tests.

Note that I also want to separate unit tests from integration tests. The latter will need an access to the Oracle database, to execute “real” tests, but my main concern (and this is the purpose of this question) is that almost all of my unit tests are not run in isolation today.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:52:07+00:00Added an answer on May 17, 2026 at 12:52 am

    Use an in-memory / Java database for testing. This will ensure the tests are closer to the real world than if you try to ‘abstract away’ the database in your test. Probably such tests are also easier to write and maintain. On the other hand, what you probably do want to ‘abstract away’ in your tests is the UI, because UI testing is usually hard to automate.

    The Oracle syntax you posted works well with the H2 database (I just tested it), so it seems H2 supports the Oracle syntax better than HSQLDB. Disclaimer: I’m one of the authors of H2. If something doesn’t work, please post it on the H2 mailing list.

    You should anyway have the DDL statements for the database in your version control system. You can use those scripts for testing as well. Possibly you also need to support multiple schema versions – in that case you could write version update scripts (alter table…). With a Java database you can test those as well.

    By the way, you don’t necessarily need to use the in-memory mode when using H2 or HSQLDB. Both databases are fast even if you persist the data. And they are easy to install (just a jar file) and need much less memory than Oracle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I imagine there are many of you out there who have developed an application
I have an application that has many different types of objects that each persist
I have an application where I have potentially many processes must send a message
We have a project with many dll files which get loaded when the application
I have inherited a VB6/Access application that we have developed and sold for many
I have a legacy VB6 application that was built using MSDE. As many client's
When designing an application, does there come a point where you have too many
Many applications have grids that display data from a database table one page at
In my application, a user has_many tickets. Unfortunately, the tickets table does not have
I have a few C# .dll projects which are common to many applications. Currently,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.