summaryrefslogtreecommitdiff
path: root/examples/cppunittest/HelperMacrosTest.cpp
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-12-16 13:53:51 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-12-16 14:05:07 +0100
commit4e529c6a6569d1f352e02af16e53aba7ae7bdc1a (patch)
treebbbb7cfe6d872406cfa38381f91e6411ab9d6822 /examples/cppunittest/HelperMacrosTest.cpp
parent923e2a837d515eb0d33792aba8bbb839f0012067 (diff)
downloadcppunit-4e529c6a6569d1f352e02af16e53aba7ae7bdc1a.tar.gz
implement parameterized tests
This allows to execute the same test with different parameters and treats each execution as an own test. The change consists of two parts, the TestCaller can now handle any callable which also makes it easy to generate programatically more complex test cases as well as the new CPPUNIT_TEST_PARAMETERIZED macro. That macro takes the test name as well as an iteratable, e.g. std::initializer_list. An example for this usage is: class SimpleTest : public CppUnit::TestFixture { public: CPPUNIT_TEST_SUITE(SimpleTest); CPPUNIT_TEST_PARAMETERIZED(test, {1, 2, 3, 4}); CPPUNIT_TEST_SUITE_END(); void test(int i) { CPPUNIT_ASSERT(i < 5); } }; which will execute test 4 times with the values 1 to 4.
Diffstat (limited to 'examples/cppunittest/HelperMacrosTest.cpp')
-rw-r--r--examples/cppunittest/HelperMacrosTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/cppunittest/HelperMacrosTest.cpp b/examples/cppunittest/HelperMacrosTest.cpp
index 4e83b81..2cdd3a7 100644
--- a/examples/cppunittest/HelperMacrosTest.cpp
+++ b/examples/cppunittest/HelperMacrosTest.cpp
@@ -77,6 +77,19 @@ public:
}
};
+class ParameterizedTestFixture : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ParameterizedTestFixture);
+ CPPUNIT_TEST_PARAMETERIZED(testMethod, {1, 2, 3, 4});
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ void testMethod(int /*val*/)
+ {
+ }
+};
+
#undef TEST_ADD_N_MOCK
#define TEST_ADD_N_MOCK( totalCount ) \
@@ -225,3 +238,13 @@ HelperMacrosTest::testAddTest()
suite->run( m_result );
m_testListener->verify();
}
+
+void
+HelperMacrosTest::testParameterizedTests()
+{
+ std::unique_ptr<CPPUNIT_NS::TestSuite> suite( ParameterizedTestFixture::suite() );
+ m_testListener->setExpectedStartTestCall(4);
+ m_testListener->setExpectedAddFailureCall( 0 );
+ suite->run(m_result);
+ m_testListener->verify();
+}