title: GoogleTest (gtest) for Multithreaded Programs: Best Practices
body: <p>What are the best gtest practices for multithreaded programs. I would like to spawn 2 threads, do some communication and assert various conditions.</p>
  
  <p>Easy solution:</p>
  
  <pre><code>void Func1() { ... ASSERT_EQ(...) ... }
  void Func2() { ... ASSERT_EQ(...) ... }
  
  TEST(MultiThread, Test) {
     std::thread one(Func1), two(Func2);
     one.join(); two.join();
  }
  </code></pre>
  
  <p>This pattern seems to be a bit inverted. The <code>TEST()</code> 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 <code>TEST()</code>, only comprising of two lambda definitions, will do the work. Fox extra points, can such a fixture be reused for multiple tests?</p>