Ignore row count when comparing datasets
See original GitHub issueIn 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:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much @iceberk, I’ll review ASAP!
Yes, that’s exactly what I’d like to see 😃 Created pull PR #115