mardi 2 août 2016

setting up unit tests and code coverage - build system

I'm setting up a new repo with c++ language and would like to know a proper way to handle unit tests and code coverage automation, probably through some sort of build system. Since C++ doesn't have a standard package manager, I'm having a bit difficulty deciding how should I proceed forward with existing code that works.

Let's take a hypothetical hello-world program -

function.cpp

// contains a single function

bool sayHello(bool sayIt) {
    if(sayIt) {
        std::cout << "Hello" << std::endl;
    }
    return sayIt;
}

main.cpp

// calls that single function

int main(){
    return sayHello(true);
}

test.cpp

// tests that single function with some testing
// framework ie gtest, catch ...

EXPECT(sayHello(true), true);
EXPECT(sayHello(false), false);

RUN_TESTS();

You get the idea. I've looked into my options and narrowed down to most commonly used packages. Cmake as build system, Gtest for unit-testing, gcov/lcov for coverage? But I'm still not sure how to integrate all of them in same project. This is where a package system would've worked flawlessly.

Should I be manually cloning gtest from it's github repo each time I'm running my tests (which makes sense for CI, not for local development). Or should I download a zip and manually update it with new gtest releases. In the past, I used Catch framework, which was a single header file and wasn't a headache since I manually downloaded and placed it in my project. I've no idea about how should I proceed integrating code coverage in Cmake so that it automatically produces appropriate files after running whole build. And I'll be wiring up the results to online CI and coverage services in future.

So how should I approach this problem?

Aucun commentaire:

Enregistrer un commentaire