Menu

dbunit Merge Request #3: Add support for ignored columns to compare task. (open)

Merging...

Merged

Something went wrong. Please, merge manually

Checking if merge is possible...

Something went wrong. Please, merge manually

Kyle Moore wants to merge 1 commit from /u/kyledmoore/dbunit/ to master, 2015-06-02

Useful for those testing DBs with dynamically derived columns that will change each run.

Commit Date  
[a7b827] (HEADmaster) by Kyle Moore Kyle Moore

Add support for ignored columns to compare task.

2014-06-20 14:35:23 Tree

Discussion

  • Jeff Jensen

    Jeff Jensen - 2014-11-29

    Hi,
    Regarding Compare.addIgnoreColumn(...): what are your future plans with this? What calls this method?

     
  • Kyle Moore

    Kyle Moore - 2015-01-29

    Oops, didn't realize you had responded (didn't get an email notification or anything). I needed this while unit testing at my co. so just contributed it back. I was basically just providing ant wrapper support for a feature already present in the Assertion class. See Compare's execute method where if ignore columns are present it calls Assertion.assertEqualsIgnoreCols vs. assertEquals.

    This was helpful for me, so thought I'd contribute it back. Thanks!

     
  • Jeff Jensen

    Jeff Jensen - 2015-03-15

    Appreciate the contribution...
    Would you mind explaining how to use it? I need to add doc for it too, explaining use.
    You can add a doc page too, otherwise just reply with usage examples and I'll add it as a doc page.

     
  • Kyle Moore

    Kyle Moore - 2015-03-16

    So in my case I ended up using the Ant POJOs in a JUnit test class:

    protected void compareIdpDataToExpectedDataSet(String appName) throws DatabaseUnitException, Exception {
    Compare compare = new Compare();
    compare.setFormat("xml");
    compare.setSrc(new File(testFilesPath + "/data-sets/idp-expected-" + appName + ".xml"));
    compare.addIgnoreColumn(new IgnoreColumn("OPLK"));
    compare.execute(idpDbTester.getConnection());
    }

    addIgnoreColumn is the new method. The presence of ignore columns on Compare results in Assertion.assertEqualsIgnoreCols being invoked rather than Assertion.assertEquals. In this example, I wanted to compare the data at the connection with the dataset while ignoring any columns named OPLK (as those are datetime columns that vary each run).

    Equivalently, one should be able to supply an ignoredcolumn nested element to an ant compare task. So that is the only doc change needed I think (listing "ignorecolumn" as a nested element for compare with a single attribute, "name").

    http://dbunit.sourceforge.net/anttask.html

    Hope that helps!

    Thanks,
    Kyle

     
  • Jeff Jensen

    Jeff Jensen - 2015-03-22

    Thanks for the info.

    Since DefaultColumnFilter (implements IColumnFilter) already exsists, what do you think of changing your implementation to use it instead of your new class IgnoreColumn? Were you aware of those?

    And I'm intrigued you use Compare instead of features of whatever idpDbTester is, assuming it is something like one of DBTestCase subclasses, e.g. DefaultPrepAndExpectedTestCase. They don't work for your situation?

     

Log in to post a comment.