Listing Pages: e.g. Products/Categories from a store, List of Doctors in LA in a Directory or results of a search etc.
Background: I am restructuring/refactoring/modernizing legacy application and when starting, the only type of tests that I can write are integration tests e.g. using selenium/equivalent to actually hit the page on server. Code that URGENTLY needs refactoring includes extremely complex and bloated functions that handle filtering of lists. I need integration tests to ensure that code doesn't get broken by the refactoring. As refactoring progresses, I will slowly integrate unit tests.
I understand how to create integration test to say check that product page exists and that it has relevant data. I could have a number of PREDEFINED products as seed data for db which will be reset before every test and refer to those products EXPLICITLY in test.
But, how do setup tests for some complex listing page - that filters products by price/custom attributes, doctors by specialty and city etc. + results are paginated? If I where to check this manually, I would need a significant amount of test data and spot check if the filters are behaving as expected and pagination is working. Obviously, I am trying to automate this process but I am struggling with how to link the tests with the test data.
Some of the approaches I am thinking of:
-
Set up the test data, record how results are currently displaying (before refactoring code), then hard code that in test.
Disadvantages: Hard coding test expectations that depends on larger amounts of test data seems so so fragile! It would just take adding one record to db to skew up expected results from filter!
-
Extract the sql used currently by code, run that sql in test, and compare results with those from page.
Advantages: Test will not break if record is added to database as long as sql query doesn't change.
Disadvantages: Feels to complex.
-
Rethink if the filter pages need testing and which parts?
-
...
Aucun commentaire:
Enregistrer un commentaire