Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 使用dbunit和jetty的集成测试-dbunit未填充表_Testing_Maven_Integration Testing_Dbunit - Fatal编程技术网

Testing 使用dbunit和jetty的集成测试-dbunit未填充表

Testing 使用dbunit和jetty的集成测试-dbunit未填充表,testing,maven,integration-testing,dbunit,Testing,Maven,Integration Testing,Dbunit,嗨,我正在尝试让集成测试正常工作, 我使用jetty作为容器和dbunit来填充HSQLDB内存数据库。 我用dataset.xml文件填充db的代码很有效,因为我在单元测试中使用了它,所以如果有人能看一下并给我一些建议,我将不胜感激。 下面是pom的相关部分和我的代码。 pom.xml } cheers集成测试在与jetty服务器不同的JVM中运行,因此内存中的数据库将具有不同的数据集,用于集成测试和jetty服务 最好的选择是在target/somedir中使用磁盘上的数据库,并让测试和

嗨,我正在尝试让集成测试正常工作,
我使用jetty作为容器和dbunit来填充HSQLDB内存数据库。
我用dataset.xml文件填充db的代码很有效,因为我在单元测试中使用了它,所以如果有人能看一下并给我一些建议,我将不胜感激。 下面是pom的相关部分和我的代码。

pom.xml

}


cheers

集成测试在与jetty服务器不同的JVM中运行,因此内存中的数据库将具有不同的数据集,用于集成测试和jetty服务

最好的选择是在
target/somedir
中使用磁盘上的数据库,并让测试和servlet容器通过hsql协议访问该数据库

并更改JDBCURI以引用服务器和端口

在上述方面,这似乎是有用的。尽管作者还没有将其发布到中央存储库中(遗憾)。如果您无法说服该插件的作者将其推送到central,并且您想要一个其他人可以使用的构建,那么您可能可以使用exec maven插件来启动hsqldb


另一种方法是让您的测试用例自己启动和停止jetty。

谢谢您的建议,但是当我尝试在磁盘db上使用时,我遇到了以下错误:严重:无法重新打开数据库org.hsqldb.hsqldb异常:文件输入/输出错误:target/db/MESSAGES.logYes,谢谢,很好的捕获我已经相应地更正了答案
<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();