私はMavenで構築されたSpringとHibernateを使用した永続化のプロジェクトを持っています.JunitとテストデータベースHSQLDBを使用してテストを実行しています.最初にテストを行うとき、サーバーモードでデータベースHSQLDBを初期化します.hudsonを初期化する方法はありますか?データベース、またはmavenで?
3360 次
3 に答える
2
そのためには、 DbUnitとDbUnit Maven Pluginを使用します。これを使用して、データベースをクリアし、テスト フェーズの前にデータセットを挿入したり、各テスト ケースのデータをセットアップしたりできます ( JUnit 3 の概要を参照してください。JUnit 4 の例については、このブログ投稿を参照してください)。
もう 1 つのオプションは、SQL Maven Pluginを使用することです。例のセクションには、データベースとスキーマを削除/作成し、テスト フェーズの前にデータを入力し、テスト フェーズの後にデータベースを削除する方法を示す構成があります)。
後者のアプローチでは、テスト間のデータ設定をあまり制御できないため、私は DbUnit を好みます。
于 2009-12-01T00:59:06.127 に答える
1
pomに以下を追加します。
<build>
<extensions>
<extension>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</extension>
<extension>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>/src/main/java</outputDirectory>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<export>false</export>
<drop>true</drop>
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<executions>
<execution>
<id>generate-ddl</id>
<phase>process-classes</phase>
<goals>
<!--Genera Esquema-->
<goal>hbm2ddl</goal>
<!--Genera Clases -->
<!-- <goal>hbm2java</goal> -->
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>create-schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>target/hibernate3/sql/schema.sql</srcFile>
</srcFiles>
</configuration>
</execution>
<execution>
<id>drop-db-after-test</id>
<phase>test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<sqlCommand>DROP SCHEMA public CASCADE</sqlCommand>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
</dependencies>
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<username>sa</username>
<password></password>
<url>jdbc:hsqldb:file:etc/out/test.db;shutdown=true</url>
<autocommit>true</autocommit>
<skip>${maven.test.skip}</skip>
</configuration>
</plugin>
</plugins>
</build>
そして私のデータソースへの以下:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true"
destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:etc/out/test.db;shutdown=true" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
于 2009-12-01T17:25:44.707 に答える
0
これは Hudson の Maven で行い、プロセス テスト リソース フェーズで maven-antrun-plugin をトリガーするプロファイルを使用します。私たちの場合、maven-antrun-plugin はスキーマを生成する Java クラスを実行しますが、もちろん他のオプションもあります。次のようになります。
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-database-schema-new</id>
<phase>process-test-resources</phase>
<configuration>
<tasks>
...
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
于 2009-12-01T00:42:31.450 に答える