Sobes.tech
Junior — Middle

Have you created automated tests for your code?

sobes.tech AI

Answer from AI

Yes, I have created automated tests for my code using various frameworks and approaches. In C++, libraries such as Google Test (gtest), Catch2, or Boost.Test are commonly used. Automated tests help verify the correctness of functions and classes, prevent regressions, and simplify code maintenance.

Here's an example of a simple test using Google Test:

#include <gtest/gtest.h>

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

TEST(AdditionTest, HandlesPositiveNumbers) {
    EXPECT_EQ(add(2, 3), 5);
}

int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

This test can be run automatically during the build process.