3

Are there either any xUnit (or otherwise) design patterns or anti-patterns for testing threaded code?

2

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.

  • +1 Yes, I do have the XUnit Test Patterns book. Great resource indeed. – Sardathrion Dec 6 '11 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.