jeudi 28 avril 2016

TDD - what's the approach with this sort of dependent sequence situation?

I'm currently getting to grips with Lucene indexing, and scratching my head about the "correct" approach if using TDD.

To do this you have to create an IndexWriter, produce an index based on a simple collection of texts (Strings), which are tokenized, stemmed, etc.

To look up a query in this index you have to create a DirectoryReader, make a Query, get the hits, etc.

So in the course of making my first test class (JUnit 4) I did each of these steps, one by one, making a new test method for each step in this process which ultimately produces a non-zero number of hits, if all goes well.

The problem I have is that the last test method does ALL these steps: clears the index directory, creates an IndexWriter, makes the index, etc. etc. and finally counts the hits. This last method can ultimately be tripped up by anything along the way going wrong. Furthermore, the previous methods all seem redundant...! And no "mocking" opportunities seem to present themselves...

Is this a candidate for a "test suite"? How does a TDD Pro develop "appropriate" testing for a situation like this?

Aucun commentaire:

Enregistrer un commentaire