Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mark a Google Test test-case as "expected to fail"?

I want to add a testcase for functionality not yet implemented and mark this test case as "it's ok that I fail".

Is there a way to do this?

EDIT: I want the test to be executed and the framework should verify it is failing as long as the testcase is in the "expected fail" state.

EDIT2: It seems that the feature I am interested in does not exist in google-test, but it does exist in the Boost Unit Test Framework, and in LIT.

like image 596
zr. Avatar asked Dec 26 '13 13:12

zr.


2 Answers

EXPECT_NONFATAL_FAILURE is what you want to wrap around the code that you expect to fail. Note you will hav to include the gtest-spi.h header file:

#include "gtest-spi.h"

 // ...

TEST_F( testclass, testname )
{
EXPECT_NONFATAL_FAILURE(
      // your code here, or just call:
      FAIL()
      ,"Some optional text that would be associated with"
      " the particular failure you were expecting, if you"
      " wanted to be sure to catch the correct failure mode" );
}

Link to docs: https://github.com/google/googletest/blob/955c7f837efad184ec63e771c42542d37545eaef/docs/advanced.md#catching-failures

like image 183
Michael Avatar answered Nov 15 '22 02:11

Michael


You can prefix the test name with DISABLED_.

like image 36
Joseph Mansfield Avatar answered Nov 15 '22 04:11

Joseph Mansfield