c++ - Test a specific exception type is thrown AND the exception has the right properties -


I want to check that 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" .

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:

  #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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -