Run threads in gtest

Viewed 5892

I'm starting implementing some tests using gtest. I have some methods, which request data from external, what takes some time. So I would like to do it in parallel using threads. For testing I made some simple example:

void TestThread(void) {
  ASSERT_EQ(1,2);
  boost::this_thread::sleep_for(boost::chrono::seconds(5));
  ASSERT_EQ(2,3);
}

TEST(MySuite, MyTest) {
  boost::thread myThread(TestThread);
  ASSERT_EQ(0,0);
  myThread.join();
}

int main(int argc, char** argv) {
  testing::InitGoogleTest(&argc, argv);

  return RUN_ALL_TESTS();
}

I would expect all asserts from TestThread, but the second one is never part of test result. Also the test runs less than a second. I guess, the 'boost::thread::join' does not work, but why?

Regards, Christian

1 Answers
Related