Dashboard
24th July 2010, 00:26
Hi,
I'm in the process of migrating a bunch of tests from UnitTest++ to QTestLib. I've gotten almost everything working aside from one thing - testing exceptions.
For example, using UnitTest++, I can verify the following function throws an exception using the CHECK_THROW macro.
int foo(int i)
{
if (i < 0)
throw std::invalid_argument("Invalid value for i");
// Do something
return i * 2;
}
...
// Ensure exception is thrown when negative value of i is passed
CHECK_THROW(foo(-1), std::invalid_argument);
// Ensure valid data works
CHECK(foo(0) == 0);
CHECK(foo(1) == 2);
Is there a suitable equivalent in QTestLib?
Thanks for any help.
I'm in the process of migrating a bunch of tests from UnitTest++ to QTestLib. I've gotten almost everything working aside from one thing - testing exceptions.
For example, using UnitTest++, I can verify the following function throws an exception using the CHECK_THROW macro.
int foo(int i)
{
if (i < 0)
throw std::invalid_argument("Invalid value for i");
// Do something
return i * 2;
}
...
// Ensure exception is thrown when negative value of i is passed
CHECK_THROW(foo(-1), std::invalid_argument);
// Ensure valid data works
CHECK(foo(0) == 0);
CHECK(foo(1) == 2);
Is there a suitable equivalent in QTestLib?
Thanks for any help.