Cpp testing is a package library for automated testing in C++, which allows developers to write unit and integration tests for their code. It is open-source software that provides a simple and easy-to-use syntax for creating tests and generating informative reports.
Code examples using cpp testing:
Example 1: Unit test for a function that returns the sum of two integers
#include
int add(int a, int b) { return a + b; }
// Define a test TEST(AddTest, EqualsFour) { EXPECT_EQ(add(2, 2), 4); }
// Run tests int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
In this example, we define a test for the 'add' function which takes two integers and returns their sum. The 'EXPECT_EQ' macro checks if the result of the function is equal to the expected value (4). We then run our tests using the 'RUN_ALL_TESTS' macro.
Package library: Google Test (gtest)
Example 2: Integration test for a file reading program
This example demonstrates an integration test for a file reading program that reads a file called 'test.txt' and returns its content as a string. The 'EXPECT_EQ' macro checks if the result of the function is equal to the expected output ("Hello, World!\n").
Package library: Google Test (gtest)
C++ (Cpp) testing - 30 examples found. These are the top rated real world C++ (Cpp) examples of testing extracted from open source projects. You can rate examples to help us improve the quality of examples.