dimanche 28 octobre 2018

unit testing asynchronous code and code without externally visible effects

Actually I have two questions, although a bit related: - I know that unit tests should test the public api. However if I have a close method that closes sockets and shuts down executors, however neither sockets nor executors are exposed to users of this api, should I test if this is done, or only that the method executed without error? Where is the borderline between public api/behavior and impl details? - if I test a method that performs some checks, then queues a task on executor service, then returns a future to monitor operation progress, should I test both this method and the task, even if the task itself is a private method or othervise not exposed code? Or should I instead test only the public method, but arrange for the task to be executed in the same thread by mocking an executor? In the latter case the fact that task is submitted to an executor using the execute() method would be an implementation detail, but tests would wait for tasks to complete to be able to check if the method along with it's async part works properly.

Aucun commentaire:

Enregistrer un commentaire