简体   繁体   中英

Questions about google test and assertion output (test results); can I trust when gtest says a test passed?

When I create a TEST or TEST_F test, how can I know that my assertion is actually executing?

The problem I have is, when I have an empty TEST_F , for example,

TEST_F(myFixture, test1) {}

When it runs, gtest says this test passes. I would have expected the test to fail, until I write test code. Anyway.

So, my problem is that when gtest says that when test is "OK" or that it passed, I can't trust it, because a test could "pass" if there is no test code.

It would be nice to print what my EXPECT_ or ASSERT calls are doing and then see that they pass. Problem is, if I do any std::cout calls, that seems to be out of sync with the test results at the end. The output messages are not in sync with any of my own std::cout calls.

Is there a verbose option to google test? How can I be sure the EXPECT that I coded is actually running?

You might consider looking at TDD, Test Driven Development, https://en.wikipedia.org/wiki/Test-driven_development

  • write one test => it will fail
  • write code to make the test pass => test passes

Rinse and repeat: express each requirement as a test, that initially fails. Write code to make that test pass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM