我的测试代码如下(一部分)
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就不会 有这种错,到底是哪里的问题啊?