How to unit test a paged grid

The general design of the web interface is to display a sortable grid (GridView, ListView, DataGrid) with paging. That is, the user can click on any column heading to force the records to be sorted in ascending or descending order by the column data. And the user can navigate between pages, say 10 records at a time.

  • There can be millions of database records that could potentially be mapped into a grid.
  • There are many possible filters that can be applied to data choices. The displayed records can be applied to the current user or to a date range or to a customer, department, product, order.
  • The user can sort the displayed records in any column and they can move between pages.

How would you write unit test (s) to confirm that the selected records are the correct records for this filter, this page, and this sort order?

0


source to share


1 answer


You need

  • decouple the filtering, sort it from the real source, so you can mock the data source and check if the logic returns the correct entries.
  • separate the paging logic from the grid so you can check if the search query is returning the correct indices.


This way, you can test the filtering and paging logic in separate units.

Then you can also use an automated web test to test the complete stuff (integration test).

+1


source







All Articles