有人在JWebunit集成测试里面使用过dbunit吗???
2005-09-08 17:15
447 查看
我的测试代码如下(一部分)
public class UserTest extends WebTestCase
{
private File file;
private IDatabaseConnection connection;
private IDataSet dataSet;
public UserTest()
{
super();
getTestContext().setBaseUrl("http://localhost:8080/PMV4");
setUserAgent("GUANGYU_PMV4_RCP");
}
protected void setUserAgent(final String userAgent)
{
tester.getTestContext().setUserAgent(userAgent);
}
protected void setUp() throws Exception
{
super.setUp();
// initialize database connection here
Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
Connection jdbcConnection = DriverManager.getConnection(
"jdbc:hsqldb:hsql://localhost/PMV4", "sa", "");
connection
= new DatabaseConnection(jdbcConnection);
dataSet = connection.createDataSet();
file = new File("full.xml");
FlatXmlDataSet.write(dataSet, new FileWriter(file), "GBK");
DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
}
protected void tearDown() throws DatabaseUnitException, SQLException
{
connection.close();
connection = null;
file.delete();
}
}
因为我的数据库里面有两个表,一个是TBLDEPARTMENT和TBLUSER。这个测试是只针对USER表里面的数据进行操作的。但是每次都会报下面的错误。
java.sql.SQLException: Integrity constraint violation FK7F3BC9B09D1E094E table: TBLDEPARTMENT
at org.hsqldb.jdbc.jdbcUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at org.dbunit.database.statement.SimpleStatement.executeBatch(SimpleStatement.java:54)
at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:112)
at com.guangyu.pmv4.webapp.view.UserCSTest.setUp(UserCSTest.java:52)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
本人对数据库不太在行,有人知道是哪里的问题吗?
如果我把CLEAN_INSERT换成别的,如REFRESH就不会 有这种错,到底是哪里的问题啊?
public class UserTest extends WebTestCase
{
private File file;
private IDatabaseConnection connection;
private IDataSet dataSet;
public UserTest()
{
super();
getTestContext().setBaseUrl("http://localhost:8080/PMV4");
setUserAgent("GUANGYU_PMV4_RCP");
}
protected void setUserAgent(final String userAgent)
{
tester.getTestContext().setUserAgent(userAgent);
}
protected void setUp() throws Exception
{
super.setUp();
// initialize database connection here
Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
Connection jdbcConnection = DriverManager.getConnection(
"jdbc:hsqldb:hsql://localhost/PMV4", "sa", "");
connection
= new DatabaseConnection(jdbcConnection);
dataSet = connection.createDataSet();
file = new File("full.xml");
FlatXmlDataSet.write(dataSet, new FileWriter(file), "GBK");
DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
}
protected void tearDown() throws DatabaseUnitException, SQLException
{
connection.close();
connection = null;
file.delete();
}
}
因为我的数据库里面有两个表,一个是TBLDEPARTMENT和TBLUSER。这个测试是只针对USER表里面的数据进行操作的。但是每次都会报下面的错误。
java.sql.SQLException: Integrity constraint violation FK7F3BC9B09D1E094E table: TBLDEPARTMENT
at org.hsqldb.jdbc.jdbcUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at org.dbunit.database.statement.SimpleStatement.executeBatch(SimpleStatement.java:54)
at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:112)
at com.guangyu.pmv4.webapp.view.UserCSTest.setUp(UserCSTest.java:52)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
本人对数据库不太在行,有人知道是哪里的问题吗?
如果我把CLEAN_INSERT换成别的,如REFRESH就不会 有这种错,到底是哪里的问题啊?
相关文章推荐
- 使用HttpUnit进行集成测试
- 使用HttpUnit进行集成测试
- 软件测试中使用HttpUnit进行集成测试(一)
- JWebUnit使用:jWebUnit是基于Java的Web应用程序的测试框架 .
- JWebUnit使用:jWebUnit是基于Java的Web应用程序的测试框架
- 使用HttpUnit进行集成测试(二)
- 使用HttpUnit进行集成测试
- 使用HttpUnit进行集成测试
- Java concurrent包里面的TimeUnit使用方法
- 使用httpunit进行集成测试
- 使用HttpUnit进行集成测试
- dbunit-spring-test和maven-dbunit-plugin使用
- 使用HttpUnit进行集成测试
- 使用JWebUnit应注意的2个问题,并不是所有的网站都适合用JWebUnit的!
- 使用HttpUnit进行集成测试
- 教程:在iOS项目里面集成使用GHUnit。
- 使用HttpUnit进行集成测试
- 使用HttpUnit进行集成测试
- 使用unittest里面的discover()方法组织测试用例
- 使用HttpUnit进行集成测试