I want to run integration tests on my store filters e.g.
I filter by price and by different product attributes
are there pattern or best practices on how to assert on such a test, I’ll illustrate an example:
Say I am calling a Repository.GetOnlyTShirtsWithColorRed() in my test db I have all the possible types of items.
I may get more then 1 item back but I want to assert that they all have a Red Color and they are all T-Shirts
I have read in many books that looping and iterating in tests in bad practice but how else may I assert that no mistake was done by my code, in a more complex query this may help to catch the bugs
From what I read – you want to test that your repository implementation works with a real DB – aka integration tests.
If the above is true, I think you’re on the right path. My assert would probably look like
As for the “best practice”, can you post a link?
AFAIK the only recommendation is to avoid complicated logic in your code (e.g. ifs and other control structures) and testing one thing per test.