springtestdbunit / spring-test-dbunit

Integration between the Spring testing framework and DBUnit
http://springtestdbunit.github.com/spring-test-dbunit/
Apache License 2.0
476 stars 238 forks source link

How about adding placeholder or expression in dataset to acturally control comparation #125

Open rbsrcy opened 8 years ago

rbsrcy commented 8 years ago

@philwebb Hi:

When Using IColumnFilter, the column specified in all rows will not be compared. In some scene ,I just want to ignore some value in some rows ,but not entired rows in one column. So I change the dbunit source code to support the placeholder.

    <dataset>
            <t_user id="2" user_name="测试2" password="test2" age="24" create_datetime="2016-09-04 16:51:43.829875" update_datetime="2016-09-04 16:51:43.829875"/>
            <t_user id="3" user_name="测试3" password="test3" age="25" create_datetime="2016-09-04 16:51:43.829875" update_datetime="2016-09-04 16:51:43.829875"/>
            <t_user id="@SKIP@" user_name="测试4" password="test4" age="26" create_datetime="@SKIP@" update_datetime="@SKIP@"/>
    </dataset>

@SKIP@ means not compare the value.

protected boolean skipCompare(String columnName, Object expectedValue, Object actualValue) 
{
    if ("@SKIP@".equals(expectedValue)) {
        return true;
    }
    return false;
}

We can also create other placeholder like @TIME.SECOND.WITHING(10)@ to compare the update_time column. But this seems has to modify the dbunit source code.