1

こんにちは、統合テストを機能させようとしています
。Jetty をコンテナーとして使用し、dbunit を使用してメモリ データベースに HSQLDB を設定しています。
データベースにデータセット.xml ファイルを設定するために使用しているコードは、単体テストで使用しているため機能します。これがポンポンと私のコードの関連部分です。

pom.xml

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.26</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <stopKey>foo</stopKey>
                <stopPort>9999</stopPort>
                <contextPath>/messages</contextPath>
                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>8080</port>
                        <maxIdleTime>60000</maxIdleTime>
                    </connector>
                </connectors>
                <webApp>
                    ${basedir}/target/messages
                </webApp>
                <scanIntervalSeconds>0</scanIntervalSeconds>
                <daemon>true</daemon>

                <scanTargetPatterns>
                    <scanTargetPattern>
                        <directory>
                           ${basedir}/target/test-classes/integrationtest/
                        </directory>
                        <includes>
                            <include>**/*.properties</include>
                            <include>**/*.xml</include>
                        </includes>
                    </scanTargetPattern>
                </scanTargetPatterns>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                    <version>1.1.1</version>
                </dependency>
                <dependency>
                    <groupId>commons-dbcp</groupId>
                    <artifactId>commons-dbcp</artifactId>
                    <version>1.2.2</version>
                </dependency>
                <dependency>
                    <groupId>org.hsqldb</groupId>
                    <artifactId>hsqldb</artifactId>
                    <version>2.2.8</version>
                </dependency>
            </dependencies>
        </plugin>



コード:

 @BeforeClass
  public static void init() throws Exception {
Context ctx = new InitialContext();

ctx.createSubcontext("jdbc");

BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(org.hsqldb.jdbcDriver.class.getName());
dataSource.setUrl("jdbc:hsqldb:mem:MESSAGES");
dataSource.setUsername("sa");
dataSource.setPassword("");

ctx.bind("jdbc/messages", dataSource);

databaseTester = new DataSourceDatabaseTester(dataSource);
createTables(databaseTester.getConnection().getConnection());

databaseTester.setDataSet(getDataSet());
databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);

databaseTester.onSetup();

}

乾杯

4

1 に答える 1

0

統合テストはJettyサーバーとは異なるJVMで実行されているため、インメモリデータベースには、統合テストとJettyサービス用に異なるデータセットがあります。

最善の策は、でディスク上のデータベースを使用しtarget/somedir、テストとサーブレットコンテナの両方がhsqlプロトコルを介してそのデータベースにアクセスできるようにすることです。

そして、サーバーとポートを参照するようにjdbcurisを変更します。

上記の目的のために、このプラグインは便利かもしれないように見えます。作者はまだ中央リポジトリに公開していませんが(残念)。プラグインの作成者にプラグインを中央にプッシュするように説得できず、他の人が使用できるビルドが必要な場合は、おそらくexec-maven-pluginを使用してhsqldbを起動できます。

別の方法は、テストケースを自分で桟橋で開始および停止させることです。

于 2012-09-03T14:00:37.753 に答える