...

/

Testing Multithreaded Code

Testing Multithreaded Code

Learn how to write tests for multithreaded code.

Not everything is easy in unit testing. Some code will be downright tricky to test. We’ll work through a couple of examples of how to test some of the more challenging situations. Specifically, we’ll write tests for code that involves threading and persistence.

Testing themes

Our approach to testing threads and persistence will be based on these two themes:

  • Rework the design to better support testing.
  • Then break dependencies using stubs and mocks.

It’s hard enough to write code that works as expected. That’s one reason to write unit tests. It’s dramatically harder to write concurrent code that works.

In one sense, testing application code that requires concurrent processing is ...