CUTI stands for C++ Unit Test Integrated
CUTI allows you to easily integrate your C++ unit tests into Visual Studio and Xcode. It is also possible to use cppunit's macros and test runner through compatibility configuration.
Visual Studio | Xcode |
---|---|
2015 | 9 |
2017 | 10 |
2019 | 11 |
- You can run your tests from within your IDE
- You have visual feedback when running your tests
- It is easier to use your IDE tools with your tests like code coverage, profiling,...
- It is easier to debug your code
- You are more likely to run your tests
- Use CMake >= 3.2
- The code to test must be compiled as a library (static or shared)
- include CUTI's CMakeLists.txt
include(${PATH_TO_CUTI_ROOT_DIR}/CMakeLists.txt)
- Create a test target
cuti_add_test_target(test_project_name project_to_test list_of_test_files_cpp)
- That's it! Take a look at ./test/testDynamicLib/CMakeLists.txt for an example
There is a toy project in the test directory to show how to use Cuti.
include(${PATH_TO_CUTI_ROOT_DIR}/CMakeLists.txt)
#create your library (SHARED or STATIC)
add_library(MyLib SHARED ${MyLib_source_files})
#Create 'MyLibTest' test target to test MyLib
cuti_add_test_target(MyLibTest MyLib ${MyLibTest_source_files})
#include "Cuti.h"
TEST_CLASS(TestClass) {
public:
/**
* Optional. Executed before every test case
*/
SET_UP() {
//...
}
/**
* Optional. Executed after every test case
*/
TEAR_DOWN() {
//...
}
void testSimpleAssert() {
ASSERT(true);
}
/**
* Test suit declaration and test case registration
*/
BEGIN_TESTS_REGISTRATION(TestClass);
TEST(testSimpleAssert);
END_TESTS_REGISTRATION();//must be the last statement in the class
};
By default, CUTI's creates a test target for its front end and Xcode or Visual Studio unit test framework. This behavior can be customized for compatibility.
- CUTI_FRONT_END can be set to CUTI or CPPUNIT
- CUTI: use macros starting by CUTI_
- CPPUNIT: allow to use macros starting by CPPUNIT_. Useful if your codebase was using cppunit and you don't want to re-write everything.
- CUTI_BACK_END can be set to CUTI or CPPUNIT
- CUTI: use Xcode or Visual Studio unit test framework as test runner
- CPPUNIT: use cppunit as test runner. Useful if you want to run your unit tests on a platform not supported by Xcode and Visual Studio.
Templates are available in the test directory
- TemplateFreeStanding.cpp : Shows how to write a test class when using CUTI_FRONT_END=CUTI
- TestTemplate.cpp : Shows how to write a test class when using CUTI_FRONT_END=CPPUNIT
Issues and merge requests are welcome !
- "Message: A 64-bit test cannot run in a 32-bit process. Specify platform as X64 to force test run in X64 mode on X64 machine."
- By default Visual Studio tries to run the unit tests target with a 32 bits test runner. But if you are compiling in 64 bits this will fail. To fix this go to:
Test -> Test Settings -> Default Processor Architecture -> X64
- By default Visual Studio tries to run the unit tests target with a 32 bits test runner. But if you are compiling in 64 bits this will fail. To fix this go to:
- No test case in my test suite
- Xcode only show test cases starting by "test". To fix either rename your test case or define CUTI_PREPEND_TEST. Take a look at TestLibInt.cpp for an example.