Google-Test für Funktionen


#include <cmath>
#include <iostream>

#include "gtest/gtest.h"  // googletest includes

int add( int a, int b)
{
  return ( a + b );
}

int main(int argc, char* argv[])
{
  testing::InitGoogleTest(&argc, argv); // initialize Google Test Framework
  return RUN_ALL_TESTS();
}

TEST(Addition, CanAddTwoNumbers_1) // define test ( name, sub-name )
{
  ASSERT_EQ( 3, add(1, 1) ); // assert stops further execution if failure
  ASSERT_EQ( 5, add(2, 2) );
}

TEST(Addition, CanAddTwoNumbers_2)
{
  EXPECT_TRUE(add(2, 1) == 4); // expect continues furher execution if failure
  EXPECT_EQ( 5, add(2, 2) );
}

Vorgehen:




GDuckeck 2019-08-01