Skip to the content.

C++

Unit-Test Frameworks

Google Test

TODO

C++14 features

Catch

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

TEST_CASE("A year is not a leap year if it is not divisible by 4", "[leap]") {
    REQUIRE( is_leap_year(2015) == false );
}

TEST_CASE("A year is a leap year if it is divisible by 4 but not by 100", "[leap]") {
    REQUIRE( is_leap_year(2016) == true );
}

TEST_CASE("A year is not a leap year if it is divisible by 100 but not by 400", "[leap]") {
    REQUIRE( is_leap_year(1900) == false );
}

TEST_CASE("A year is a leap year if it is divisible by 400", "[leap]") {
    REQUIRE( is_leap_year(2000) == true );
}
TODO Fournir plus d'exemples sur la puissance de Catch

Mettle

#include <mettle.hpp>

mettle::suite<> basic("Leap Year", [](auto &_) {

  _.test("A year is not a leap year if it is not divisible by 4", []() {
    mettle::expect(false, is_leap_year(2015));
  });

  _.test("A year is a leap year if it is divisible by 4 but not by 100", []() {
    mettle::expect(true, is_leap_year(2016));
  });

  _.test("A year is not a leap year if it is divisible by 100 but not by 400", []() {
    mettle::expect(false, is_leap_year(1900));
  });

  _.test("A year is a leap year if it is divisible by 400", []() {
    mettle::expect(true, is_leap_year(2000));
  })
}

lest

lest errors escape testing

https://github.com/martinmoene/lest

Tester les invariants

Couverture de données

Les premiÚres implémentations en C++ ont été C++ QuickCheck, puis AutoCheck.

Aujourd’hui, c’est le projet RapidCheck qui est le plus actif et propose le plus de fonctionnalitĂ©s.

RapidCheck

TODO Fournir quelques exemples

Mock

Google Mock

TODO Fournir exemples

Trompeloeil

trompeloeil logo

Mockaron

C++ Great Practices

PrĂ©voire un build-type “Coverage”

  Release Debug Coverage
assert() -D NDEBUG   -D NDEBUG
Optimisation -Ofast
(or any other)
-O0 -fno-inline -O0 -fno-inline

Autres options de compilation

Les mĂȘmes pour les trois build types

Pousser les bugs à se révéler

Utiliser différents compilateurs

Multiplier les combinaisons

Definition of Done (DoD)