2015-04-08 23 views
7

Projem için google Sınama çerçevesi kullanıyorum. olarak kullanılarakGoogle test istisnası atlatma iletisini al

throw DerivedClassException("message"); 

ve test çerçeve içinde: Ben kodundan durum atma am

ASSERT_THROW(commond(), DerivedClassException); 

Ben what() API ile mesaj almak istiyorum. Özel durumun istisna mesajını almanın herhangi bir yolu.

cevap

8

istisnayı kontrol etmenin tek yolu testinde yakalamak şudur:

void test_foo(MyTest, TestException) 
{ 
    try 
    { 
    functionThatThrowsException(); 
    FAIL(); 
    } 
    catch(const DerivedClassException& err) 
    { 
    // check exception 
    ASSERT_STREQ("error message", err.what()); 
    } 
} 
İlgili konular