Using multiple threads in tests
Adding multiple threads to your tests presents challenges that you need to be aware of. I’m not talking about running the tests themselves in multiple threads. The testing library registers and runs the tests and it will remain single-threaded. What you need to understand are the problems that can arise when multiple threads are created inside of a test.
To understand these problems, let’s create a test that uses multiple threads so that you can see exactly what happens. We’ll be working with the unit test library project in this section so, first, add a new test file called Thread.cpp
. The project structure should look like this after you’ve added the new file:
MereTDD project root folder
Test.h
tests folder
main.cpp
Confirm.cpp
...