c++ - Test a specific exception type is thrown AND the exception has the right properties -
I want to check that How best is this applicable in GPES? I mostly respond to the other Lilichiae but you should also verify that wrong < / Em> Exception type is not thrown: MyException is thrown in a certain matter.
EXPECT_THROW Good here. But I also want to see that the exception is a specific state like
e.msg () == "cucumber overflow" .
#include & lt; Stdexcept & gt; #include "gtest / gtest.h" structure foo {int bar (int i) {if (i> 100) {std :: out_of_range ("out of range"); } Came back; }}; Test (foo_test, out_of_range) {eff F; {F. Bar (111); Failed () & lt; & Lt; "Expected std :: out_of_range"; } Hold (std :: out_of_range const & Google) {EXPECT_EQ (err.what ()), std :: string ("out of range"); } Hold (...) {FAIL () & lt; & Lt; "Expected std :: out_of_range"; }} Int main (int argc, char ** argv) {:: testing :: InitGoogleTest (& argc, argv); Return RUN_ALL_TESTS (); }
Comments
Post a Comment