views:

191

answers:

1

A common web UI design is to display a sortable grid (GridView, ListView, DataGrid) with paging. That is, the user can click on any column header to cause the records to be sorted in ascending or descending order on that column's data. And, the user can navigate among the pages of, say, 10 records at a time.

  • There may be millions of database records that could potentially be displayed on the grid.
  • There are many possible filters that could be applied to the data selection. The displayed records might apply to the current user, or to a date range, or to a customer, department, product, order.
  • The user can sort the displayed records on any column, and they can navigate among pages.

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

+1  A: 

You will have to

  • decouple the filtering, sorting from the actual source so that you can mock the datasource and test if the logic returns the correct records.
  • decouple the paging logic from the grid so that you can test if the paging gives the right indexes back.

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

Next you could also use a automatic webtest to test the complete stuff (integration test).

Michiel Overeem