Testing with a Fake Searcher

A search returns a set of results. When something returns a list of values, I'm always interested to see how it will behave when it returns 0, 1, or an arbitrary number.

Because this is a unit test, I don't want to depend on the real Searcher implementations; I'd rather create my own for testing purposes. This lets me control behavior in a fine-grained way. Here I'll create a new Searcher called TestSearcher. We'll have the query string be an integer, which will tell how many items to return. We'll name the items "a0" (for first author), "t1" (second title), and so on.

But first, a test. (Notice this is a test of our testing class, not of our GUI.)

 public void testTestSearcher() { assertEquals(new Query("1").getValue(), ...

Get Extreme Programming Installed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.