Re: [googletest] Why Googletest stops when it founds an Exception?

1,325 views
Skip to first unread message

Joey Oravec

unread,
Jun 26, 2012, 11:33:47 PM6/26/12
to Daniel Ampuero, googletes...@googlegroups.com
Yes -- the problem is that google test runs everything within the same process, so it's very easy for a serious failure to take down the entire process.

I posted a patch (against an older version of gtest) that was discussed but not accepted: https://groups.google.com/forum/?fromgroups#!topic/googletestframework/HYxAy1-HYAU

You'd need to run each test in a separate process to really guarantee that a single test cannot bring down the entire system. I don't think there's a philosophical objection; it's just rather complex to implement.

-joey

On Tue, Jun 26, 2012 at 8:19 PM, Daniel Ampuero <danie...@gmail.com> wrote:
Hi,

I'm testing several testing frameworks, and I'm currently testing this one. One thing I found interesting on some frameworks is the ability to not stop when an exception occurs, so at the end all test can be executed. Nevertheless, I found that Googletest simply stop when it founds an exception during the program execution. The code I'm using is the following:

TEST(FailingTest, DivisionByZero)
{
    EXPECT_EQ(1/0, 2/0);
}

It will obviously fail, but I wanted to continue with the remaining tests.

Is there any way to tell the framework to not stop when an exception occur? Any parameter that can be passed to the program? If it is not possible, why? Is there any philosophical reason for this behaviour?

Thanks in advance!


Daniel Ampuero

unread,
Jun 28, 2012, 3:48:11 PM6/28/12
to Joey Oravec, googletes...@googlegroups.com
This is very disappointing since I've really liked the framework. I saw some things with "EXPECT_*", but I thinks is not a propper workarround to solve the problem.

2012/6/26 Joey Oravec <joeyo...@gmail.com>



--
Daniel Ampuero Anca

Greg Miller

unread,
Jun 28, 2012, 9:07:40 PM6/28/12
to Daniel Ampuero, Joey Oravec, googletes...@googlegroups.com
Depending on your platform division by zero will kill the process with a signal, not throw an exception. Luckily that causes the process to exit with a non-zero exit status, so it's clear that the process died and the tests did not pass.

Greg

Zhanyong Wan (λx.x x)

unread,
Jun 29, 2012, 1:33:59 PM6/29/12
to Greg Miller, Daniel Ampuero, Joey Oravec, googletes...@googlegroups.com
http://code.google.com/p/googletest/wiki/AdvancedGuide#Disabling_Catching_Test-Thrown_Exceptions

By default, Googletest does catch *exceptions* thrown by a test and
continue with the next test.

In your case, Daniel, your code is not throwing a C++ exception. It's
probably an SEH on Windows and a signal on Linux. That should be rare
enough in practice (if your tests do that a lot, it may be an
indication of a much bigger problem.)
--
Zhanyong

Daniel Ampuero

unread,
Jun 29, 2012, 1:59:30 PM6/29/12
to Zhanyong Wan (λx.x x), Greg Miller, Joey Oravec, googletes...@googlegroups.com
Hi Wan,

You are right, it's throwing a signal, not an exception. It's my fault to confuse them. Nevertheless, now I've studied the framework a bit better, I get the following conclusions:
  • Being able to not die during a test due a signal is a desired feature for many programmers. There are many frameworks providing this feature (CxxTest is an example). 
  • Nevertheless, die after a killing signal could be good, since such error has major importance and cannot stay unattended.

So, I think is a matter of what you want. I think is worth to see Joey's work, although it only works on Windows, it could be offered as a plug-in (if possible, of course), for those who want to prevent the test stop when a fatal signal appear.

Regards


2012/6/29 Zhanyong Wan (λx.x x) <w...@google.com>



--
Daniel Ampuero Anca
Reply all
Reply to author
Forward
0 new messages