79139869

Date: 2024-10-30 06:25:36
Score: 0.5
Natty:
Report link

In CPPUnit, there's no built-in way to mark tests as "skipped" directly, as it doesn’t have native support for test skipping.

@Shahul Hameed statement is correct!

What you can try to do one way is that dynamically adding tests based on conditions.

class CustomTest : public CppUnit::TestFixture {
    CPPUNIT_TEST_SUITE(CustomTest);
    CPPUNIT_TEST(test1);
    CPPUNIT_TEST(test2);
    CPPUNIT_TEST_SUITE_END();

public:
    void test1() {
        CPPUNIT_ASSERT(true);
    }

    void test2() {
        CPPUNIT_ASSERT(true);
    }
};

int main(int argc, char* argv[]) {
    CppUnit::TextUi::TestRunner runner;

    bool skipTests = false;

    if (argc > 1 && std::string(argv[1]) == "--skip") {
        skipTests = true;
    }

    if (!skipTests) {
        runner.addTest(MyTest::suite());
    } else {
        std::cout << "Tests were skipped due to command line argument.\n";
    }

    runner.run();
    return 0;
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Shahul
  • Low reputation (0.5):
Posted by: Shelton Liu