DBunit - DbAssertionFailedError
DBunit - DbAssertionFailedError
对 DBUnit 感到沮丧 :( 有人知道为什么我会得到 dbAssertionFailedError driverClass is null for the below 吗?dbunitData.xml 包含一行测试数据。我知道与数据库的连接很好但是该错误似乎是由 assertequals 触发的。
public class ExtendDBTestCaseTest extends DBTestCase
{
public static final String TABLE_LOGIN = "salarydetails";
private FlatXmlDataSet loadedDataSet;
private SalaryCalculation salaryCalculation;
@SuppressWarnings("deprecation")
protected IDataSet getDataSet() throws Exception
{
loadedDataSet = new FlatXmlDataSet(this.getClass().getClassLoader()
.getResourceAsStream("dbunitData.xml"));
return loadedDataSet;
}
protected void setUp() throws Exception
{
setUpDatabase();
}
@SuppressWarnings("deprecation")
private void setUpDatabase() throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection jdbcConnection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/salary", "someUser", "somePass");
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
IDataSet dataSet = getDataSet();
try
{
getSetUpOperation().execute(connection, dataSet);
}
finally
{
connection.close();
}
}
protected DatabaseOperation getSetUpOperation() throws Exception{
return DatabaseOperation.REFRESH;
}
public void testCalculatorNeg() throws Exception
{
salaryCalculation = new SalaryCalculation();
int salary = salaryCalculation.calculator("12345");
assertEquals(0, salary);
}
}
经过反复试验,我很沮丧地回答了我自己的问题。只需要使用 loadedDataSet.endDataSet() 添加一个拆卸方法;现在工作正常!
对 DBUnit 感到沮丧 :( 有人知道为什么我会得到 dbAssertionFailedError driverClass is null for the below 吗?dbunitData.xml 包含一行测试数据。我知道与数据库的连接很好但是该错误似乎是由 assertequals 触发的。
public class ExtendDBTestCaseTest extends DBTestCase
{
public static final String TABLE_LOGIN = "salarydetails";
private FlatXmlDataSet loadedDataSet;
private SalaryCalculation salaryCalculation;
@SuppressWarnings("deprecation")
protected IDataSet getDataSet() throws Exception
{
loadedDataSet = new FlatXmlDataSet(this.getClass().getClassLoader()
.getResourceAsStream("dbunitData.xml"));
return loadedDataSet;
}
protected void setUp() throws Exception
{
setUpDatabase();
}
@SuppressWarnings("deprecation")
private void setUpDatabase() throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection jdbcConnection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/salary", "someUser", "somePass");
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
IDataSet dataSet = getDataSet();
try
{
getSetUpOperation().execute(connection, dataSet);
}
finally
{
connection.close();
}
}
protected DatabaseOperation getSetUpOperation() throws Exception{
return DatabaseOperation.REFRESH;
}
public void testCalculatorNeg() throws Exception
{
salaryCalculation = new SalaryCalculation();
int salary = salaryCalculation.calculator("12345");
assertEquals(0, salary);
}
}
经过反复试验,我很沮丧地回答了我自己的问题。只需要使用 loadedDataSet.endDataSet() 添加一个拆卸方法;现在工作正常!