question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore row count when comparing datasets

See original GitHub issue

In tests I would like to verify only small subset of existing rows in the table. Let’s say I have ‘users’ table and I need to insert common users rows for most of the tests:

common.yml

users:
  - id: 1
    name: User1
  - id: 2
    name: User2

Then in some test I want to check update of the user name. For example the test will update name of user with id = 2 from ‘User2’ to ‘Another user 2’. So I would like to have the following in expected dataset:

expected.yml

users:
  - id: 2
    name: Another user 2

In current implementation the test will fail because row count is obviously different - 1 row expected and 2 rows in actual dataset. I was able to implement a workaround using PrimaryKeyFilteredTableWrapper in DataSetAssertion class:

public class DataSetAssertion {
    private static final DataSetAssert INSTANCE = new DataSetAssert();

    private static ITable filterActualDataset(ITable expectedDataSet, ITable actualDataSet) throws DataSetException {
        String pkName = actualDataSet.getTableMetaData().getPrimaryKeys()[0].getColumnName();
        Set<Object> pkList = new HashSet<>();
        for (int i = 0; i < expectedDataSet.getRowCount(); i++) {
            pkList.add(expectedDataSet.getValue(i, pkName));
        }

        return new PrimaryKeyFilteredTableWrapper(actualDataSet, pkList);


    }

    public static void assertEqualsIgnoreCols(ITable expectedDataSet,
                                              ITable actualDataSet, String[] ignoreCols)
            throws DatabaseUnitException {
        INSTANCE.assertEqualsIgnoreCols(expectedDataSet, filterActualDataset(expectedDataSet, actualDataSet), ignoreCols);
    }
}

Can we add some flag/enum to com.github.database.rider.core.api.dataset.ExpectedDataSet annotation to change default checking logic?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rmpestanocommented, Jan 24, 2019

Thank you very much @iceberk, I’ll review ASAP!

1reaction
iceberkcommented, Jan 24, 2019

Yes, that’s exactly what I’d like to see 😃 Created pull PR #115

Read more comments on GitHub >

github_iconTop Results From Across the Web

SprigngTestDBUnit. How to ignore row order when comparing ...
I'm using com.github.springtestdbunit to conduct persistence tests on my DAO layer. The problem is that i don't know in which order data will...
Read more >
Ultimate Guide - Compare two lists or datasets in Excel
Learn how you can compare two lists, two columns or two data sets in Excel. We will look at conditional formatting, formulas and...
Read more >
Comparing data sets without using a template - IBM
Skip count : If required, specify a Skip Count for the data. The comparison starts after skipping the number of records specified in...
Read more >
How to do a quick estimated compare of data in two large SQL ...
In this article, we'll describe a simple task to validate the table (row count only) between the databases on different SQL instances.
Read more >
The comparedf function
To compare these datasets, simply pass them to the comparedf() function: comparedf(df1, df2) ... We've changed row order, so let's compare by the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found