Dragonfly
Dragonfly

Reputation: 217

DBunit - DbAssertionFailedError

Getting frustrated with DBUnit :( Anyone know why I would get dbAssertionFailedError driverClass is null for the below please? dbunitData.xml contains the test data with one row. I know that the connection to the database is fine but the error seems to be triggered by the 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);
    }
}

Upvotes: 1

Views: 742

Answers (1)

Dragonfly
Dragonfly

Reputation: 217

Frustratingly I answered my own question after more trial and error. Just needed to add a teardown method with loadedDataSet.endDataSet(); and now works fine!

Upvotes: 1

Related Questions