title: How to catch an assert with Google test?
body: <p>I'm programming some unit test with the Google test framework. But I want to check whether some asserts are well placed and are useful. Is there a way to catch an assert in Google test?</p>
  
  <p>Example code under test:</p>
  
  <pre><code>int factorial(int n){
      assert(n &gt;= 0);
      //....
  }
  </code></pre>
  
  <p>And then the test:</p>
  
  <pre><code>#include &lt;gtest/gtest.h&gt;
  TEST(FactorialTest,assertNegative){
      EXPECT_ANY_THROW({
           factorial(-1);
      });
  }
  </code></pre>
  
  <p>But <code>EXPECT_ANY_THROW</code> doesn't catch the assert but only exceptions. I'm searching for a solution to catch asserts.</p>