I’m developing a new project. This is what has been done until now:
- A technical design.
- The model classes (data classes).
- All the interfaces in the project (but no implementations yet).
Next thing I wanna do is implementing the methods from the skeleton (the high level methods) down to the nested objects. Nevertheless, I want to create a unit test for each method before I write the implementation. There won’t be any problem to implement the high level methods first, because I’m gonna work with interfaces and bind the concrete implementation only in an external Java configuration file using DI.
The first method I’m gonna implement is called
lookForChanges() and it both accepts and returns void. This method is called by Spring’s scheduler (@Scheduled), and it manages the whole process: it retrieves data from the DB, retieves data from a web service, compares them, and if there were any changes then it updates the database and sends a JMS message to a client. Of course, it doesn’t do all those things by itself but it calls the relevant classes and methods.
So the first problem I’d had is how to create a unit test to a void method. In all tutorials always the tested methods accept parameters and return a result. I’ve found an answer for that in this question. He says that even if there’s no result to check, at least one can make sure that the methods inside the tested method were called and with the correct order of parameters.
I sort of liked this answer, but the problem is that I’m working TDD so in contast to the guy who asked this question, I’m writing the test before implementing the tested method, so I don’t know yet which methods and in what order it will use. I can guess, but I will only be sure about that once the method will have been already implemented.
So, how can I test a void skeleton method before I implement it?