Add CppUnit test with just a simple dummy failing test
This commit is contained in:
parent
5fd3b2c425
commit
4014158e8f
6 changed files with 116 additions and 0 deletions
|
@ -57,3 +57,6 @@ ENDIF(BUILD_TDTOOL)
|
|||
IF(BUILD_TDADMIN)
|
||||
ADD_SUBDIRECTORY(tdadmin)
|
||||
ENDIF(BUILD_TDADMIN)
|
||||
|
||||
ENABLE_TESTING()
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
|
|
8
telldus-core/tests/CMakeLists.txt
Normal file
8
telldus-core/tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
ADD_SUBDIRECTORY(common)
|
||||
|
||||
ADD_EXECUTABLE(TestRunner cppunit.cpp)
|
||||
TARGET_LINK_LIBRARIES(TestRunner cppunit TelldusCommonTests)
|
||||
ADD_DEPENDENCIES(TestRunner TelldusCommonTests)
|
||||
|
||||
ADD_TEST(Tests ${CMAKE_CURRENT_BINARY_DIR}/TestRunner)
|
||||
|
9
telldus-core/tests/common/CMakeLists.txt
Normal file
9
telldus-core/tests/common/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
FILE(GLOB SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*Test.cpp" )
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
|
||||
|
||||
ADD_LIBRARY(TelldusCommonTests SHARED ${SRCS} )
|
||||
|
||||
TARGET_LINK_LIBRARIES( TelldusCommonTests TelldusCommon )
|
||||
ADD_DEPENDENCIES( TelldusCommonTests TelldusCommon )
|
||||
|
31
telldus-core/tests/common/StringsTest.cpp
Normal file
31
telldus-core/tests/common/StringsTest.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "StringsTest.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (StringsTest);
|
||||
|
||||
void StringsTest :: setUp (void)
|
||||
{
|
||||
}
|
||||
|
||||
void StringsTest :: tearDown (void)
|
||||
{
|
||||
}
|
||||
|
||||
void StringsTest :: addTest (void)
|
||||
{
|
||||
// check subtraction results
|
||||
CPPUNIT_ASSERT_EQUAL (1, 1);
|
||||
CPPUNIT_ASSERT_EQUAL (1, 2);
|
||||
}
|
||||
|
||||
void StringsTest :: subTest (void)
|
||||
{
|
||||
// check addition results
|
||||
CPPUNIT_ASSERT_EQUAL (1, 1);
|
||||
}
|
||||
|
||||
|
||||
void StringsTest :: equalTest (void)
|
||||
{
|
||||
// test successful, if true is returned
|
||||
CPPUNIT_ASSERT (1 == 1);
|
||||
}
|
26
telldus-core/tests/common/StringsTest.h
Normal file
26
telldus-core/tests/common/StringsTest.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef STRINGSTEST_H
|
||||
#define STRINGSTEST_H
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "Strings.h"
|
||||
|
||||
class StringsTest : public CPPUNIT_NS :: TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE (StringsTest);
|
||||
CPPUNIT_TEST (addTest);
|
||||
CPPUNIT_TEST (subTest);
|
||||
CPPUNIT_TEST (equalTest);
|
||||
CPPUNIT_TEST_SUITE_END ();
|
||||
|
||||
public:
|
||||
void setUp (void);
|
||||
void tearDown (void);
|
||||
|
||||
protected:
|
||||
void addTest (void);
|
||||
void subTest (void);
|
||||
void equalTest (void);
|
||||
};
|
||||
|
||||
#endif //STRINGSTEST_H
|
39
telldus-core/tests/cppunit.cpp
Normal file
39
telldus-core/tests/cppunit.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <cppunit/CompilerOutputter.h>
|
||||
#include <cppunit/XmlOutputter.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
#include <cppunit/TestRunner.h>
|
||||
#include <cppunit/BriefTestProgressListener.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
// informs test-listener about testresults
|
||||
CPPUNIT_NS :: TestResult testresult;
|
||||
|
||||
// register listener for collecting the test-results
|
||||
CPPUNIT_NS :: TestResultCollector collectedresults;
|
||||
testresult.addListener (&collectedresults);
|
||||
|
||||
// register listener for per-test progress output
|
||||
CPPUNIT_NS :: BriefTestProgressListener progress;
|
||||
testresult.addListener (&progress);
|
||||
|
||||
// insert test-suite at test-runner by registry
|
||||
CPPUNIT_NS :: TestRunner testrunner;
|
||||
testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ());
|
||||
testrunner.run (testresult);
|
||||
|
||||
// output results in compiler-format
|
||||
CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);
|
||||
compileroutputter.write ();
|
||||
|
||||
std::ofstream xmlFileOut("cpptestresults.xml");
|
||||
CPPUNIT_NS :: XmlOutputter xmlOut(&collectedresults, xmlFileOut);
|
||||
xmlOut.write();
|
||||
|
||||
// return 0 if tests were successful
|
||||
return collectedresults.wasSuccessful () ? 0 : 1;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue