Code Monkey home page Code Monkey logo

cuti's Introduction

Build status Build Status

CUTI

CUTI stands for C++ Unit Test Integrated

What?

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
2013 6.4
2015 7.3
2017 8.3
_ 9.4
_ 10
Visual Studio Tests Results Xcode Tests Results

Why?

  • 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

Prerequisite

  • Use CMake >= 3.2
  • The code to test must be compiled as a library (static or shared)

How?

  • Add CUTI's root directory to your CMakeLists.txt
add_subdirectory(${PATH_TO_CUTI_ROOT_DIR} ${CMAKE_BINARY_DIR}/cuti)
  • Create a test target
cuti_creates_test_target(test_project_name project_to_test list_of_test_files_cpp)

Example

There is a toy project in the test directory to show how to use Cuti.

CMakeLists.txt

add_subdirectory(${PATH_TO_CUTI_ROOT_DIR} ${CMAKE_BINARY_DIR}/cuti)
#create your library (SHARED or STATIC)
add_library(MyLib SHARED ${MyLib_source_files})
#Create 'MyLibTest' test target to test MyLib
cuti_creates_test_target(MyLibTest MyLib ${MyLibTest_source_files})

TestClass.cpp

#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
};

CMake arguments

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

Templates are available in the test directory

Contributing

Issues and merge requests are welcome !

FAQ:

Visual Studio

  • "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

Xcode

  • 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.

cuti's People

Contributors

baubry-arturia avatar k-brac avatar ppfister-arturia avatar thegs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.