lundi 23 mars 2015

How to Unit Test a Long-Running Function Call?

So I have a class that I'm calling MessageEngine. This MessageEngine is going to have a single public function, called StartEngine. The Engine will, every X seconds, poll server A, transform the results, and post to server B. I have mocks for Server A and Server B's interfaces, so that I can test the MessageEngine in isolation. However, the StartEngine call never actually terminates; the idea is that it run in perpetuity. How can I best capture this in Unit Tests (using NUnit, if it matters)? I don't want to expose the internals of the MessageEngine just to make it more testable.


My first thought is to just call StartEngine, wait an arbitrary amount of time, then assert the results were posted to Server B's mock. Then I can call something like StartEngine.Abort to shut down the engine. Is there a better pattern for testing these sorts of behaviours?


Aucun commentaire:

Enregistrer un commentaire