Are there either any xUnit (or otherwise) design patterns or anti-patterns for testing threaded code?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Have you seen a http://xunitpatterns.com? A lot of great material there.
In my experience dealing with threaded behavior in tests just makes things needlessly complicated and not worth the effort. Try to isolate tasks from each other by using mocks/stubs as much as you can.
There is one particular pattern however that helped me a lot: design by contract. Which I implemented by inserting assertions in the application code and stress testing the system in attempt to trigger their violations.
YMMV of course, but for my projects this approach (isolation and stress testing) proved to be more effective than trying to write tests for specific use cases.