Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A previous poster listed Liquibase as an option, however they failed to mention Liquibase's ability to define rules which run in particular contexts (<a href="http://www.liquibase.org/manual/contexts" rel="nofollow noreferrer">Contexts in Liquibase</a>). This allows you to have the schema updates not marked with any particular context and the fixtures for the unit tests marked as a context of <code>test</code>. This way, the fixtures will only be inserted when you run your unit tests.</p> <p>Here is an example of a Liquibase change set that contains the schema and the fixtures:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"&gt; &lt;changeSet author="avalade" id="1"&gt; &lt;createTable tableName="users"&gt; &lt;column autoIncrement="true" name="id" type="long"&gt; &lt;constraints nullable="false" primaryKey="true" /&gt; &lt;/column&gt; &lt;column name="email" type="varchar(255)" /&gt; &lt;/createTable&gt; &lt;/changeSet&gt; &lt;changeSet author="avalade" id="2" context="test"&gt; &lt;insert tableName="user"&gt; &lt;column name="id" value="1" /&gt; &lt;column name="email" value="test@test.com" /&gt; &lt;/insert&gt; &lt;/changeSet&gt; &lt;/databaseChangeLog&gt; </code></pre> <p>Then, if you're using Spring to manage your DAO's, you could put the following in your Application Context file that you're deploying:</p> <pre><code>&lt;bean id="liquibase" class="liquibase.spring.SpringLiquibase"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="changeLog" value="classpath:dbChangelog.xml" /&gt; &lt;/bean&gt; </code></pre> <p>For the Application Context file that you use in your unit tests, configure Liquibase with an additional context property:</p> <pre><code>&lt;bean id="liquibase" class="liquibase.spring.SpringLiquibase"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="changeLog" value="classpath:dbChangelog.xml" /&gt; &lt;property name="contexts" value="test" /&gt; &lt;/bean&gt; </code></pre> <p>This way, you can keep all of your database definitions together in one place and only insert your fixtures when you're running your test code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload