Announcement Announcement Module
Collapse
No announcement yet.
Using Derby embedded database for testing with Maven Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Derby embedded database for testing with Maven

    Hi,

    First of all, I want to say thank you to the Spring team for providing embedded database support (Derby, ...).

    Unfortunately when using Derby embedded database support for JUnit tests, that are executed from Maven Surefire, a problem with shutting down (cleaning up) the Derby database shows up.

    We've several JUnit test cases that create an embedded database on loading the application context of the test case.

    Code:
     <jdbc:embedded-database id="dataSource" type="DERBY">
            <jdbc:script location="classpath:sql/schema.sql"/>
            <jdbc:script location="classpath:sql/regelwerkdata.sql"/>
    </jdbc:embedded-database>
    Running each test case separately (e.g. from Eclipse) works without any problems. Running both from Maven Surefire (Life cycle phase test) only works for the first, and the second will fail on creating the tables (SQL DDL statements from file schema.sql).

    In my opinion, the reason for the failure comes from the Derby shutdown issued by the class DerbyEmbeddedDatabaseConfigurer that does a shutdown without dropping the database before.

    Has anyone ever used this kind of setup successfully? Any workarounds available?

    Kind regards
    Juergen

  • #2
    Similar problem here with HSQL.

    I've got two test classes, both loading the test application context which executes SQL scripts as shown above. But the second test class fails as the DB isn't shut down.

    How to create a new database for each test method (not just per class, which doesn't seem to work anyway)? Or how do you test using spring/hibernate/junit?

    Comment


    • #3
      I am not sure why you need to create db for every test run, I personally use hsql in memory db and create it once using spring jdbc initialization

      Code:
      <jdbc:initialize-database data-source="hsldbDS">
          <jdbc:script location="classpath:dbscripts/createDB.sql" />
      </jdbc:initialize-database>
      I have my db definition (sql to create db) and some initial data (insert sql) in createDB.sql , spring will do the rest by executing all the sql that is listed in createDB.sql

      Comment


      • #4
        Found a good solution later:

        http://apenchantforcheese.wordpress....in-spring-3-0/

        Works for me, at least one set up for each class.

        Comment

        Working...
        X