dimanche 22 novembre 2015

google test framework best practice to fail a test from TestEventListener

I have TestEventListener that fails a test if it take more than some limit. I have the check in the OnTestEnd where I can check test_info.result()->elapsed_time() and I trigger the error with GTEST_FAIL.

void TimeMonitor::OnTestEnd(const ::testing::TestInfo& test_info)
{
  ...

  GTEST_FAIL()
    << "This test took "
    << test_info.result()->elapsed_time() << " ms "
    << "instead the expected " << expected << " ms.";
}

This works with one very annoying exception - the error report code line points to the place where GTEST_FAIL() is. I know that this code is correct, I would like to be pointed out to the head of the test that failed instead.

How I can change the code to print the test head location?

Aucun commentaire:

Enregistrer un commentaire