GoogleTest (gtest) for Multithreaded Programs: Best Practices

时间:2017-08-04 13:14:14

标签: c++ multithreading googletest fixtures

What are the best gtest practices for multithreaded programs. I would like to spawn 2 threads, do some communication and assert various conditions.

Easy solution:

void Func1() { ... ASSERT_EQ(...) ... }
void Func2() { ... ASSERT_EQ(...) ... }

TEST(MultiThread, Test) {
   std::thread one(Func1), two(Func2);
   one.join(); two.join();
}

This pattern seems to be a bit inverted. The TEST() seems to do set-up and the helper functions seem to do the testing hard-work. Any better way to do this? I'm imagining something like a fixture that sets up the threads/joins them, and the TEST(), only comprising of two lambda definitions, will do the work. Fox extra points, can such a fixture be reused for multiple tests?

0 个答案:

没有答案