I get this output when I run my gtest
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Test
[ RUN ] Test.Foo
and it exits after this.
My code is as follows:
//Exception file
class myex : public std::runtime_error {
myex(const std::string& reason)
: std::runtime_error(reason){
}
}
//TestFile
class Test : public testing::Test {
public:
MockClass mc;
std::unique_ptr<classToTest> obj;
void SetUp(){
obj = std::make_unique<classToTest>(mc);
}
void bar() {
std::string error = "error";
throw myex(error);
}
}
TEST_F(Test, Bar) {
EXPECT_THROW(bar(), myex); //works. Print PASS.
}
TEST_F(Test, Foo) {
EXPECT_THROW(obj->fn(), myex); // doesnot work. Prints not PASS/FAIL.
}
TEST_F(Test, test1) {
obj->fn(); // prints : unknown file: error: (correctly prints the reason)
}
//ClassToTest file
class classToTest {
void fn() {
throw myex("Error has occurred");
}
}
I do not understand why the error thrown in from classToTest is identified by gtest as
Unknown File: error: C++ exception ...
And, why does it not show PASS/FAIl for the
EXPECT_THROW(fn(), myex)
but weirdly exits.
Kindly let me know if I have made any mistake and also, if you need any more information. TIA.
Aucun commentaire:
Enregistrer un commentaire