2008-09-17

mock-testing and threads

Once again was badly burned on issues with moving code across threads. JMock reported failed tests as soon as some call made through the thread boundary. Apparently, we need ExecutorService injections and tinkering with our BaseWorker pattern to keep unit-testing effectiveness and maintainer sanity at the optimum. Those injections were discussed in great detail in the JMock Cookbook.

2 comments:

Nat Pryce said...

JMock will support multithreaded code in the next version. I'll be writing about these features at http://www.natpryce.com over the next few days.

Anton S. Kraievoy said...

Well, thanks for your comment on this.
Actually we had some producer/consumer pattern which was not so easily transferrable to single-threaded test.
Anyway I've done some moves from threads with loops towards scheduled tasks with an ExecutorService instance, so this whole reading was useful anyway.