Test Fixture Design

This learning hour is for C++ and would need adapting if you are using a different programming language. We will look at two ways to write a test fixture - using GoogleTest and Catch2. We assume the participants already know GoogleTest and would like to learn about Catch2.

Session Outline

Connect: What is a test fixture for

I want 3 reasons to write a test fixture. Make sure they come up with 3 reaons before you proceed.

Connect: review test fixture in GoogleTest

Review code in master branch for TimerExpiryRefactoringKata. Look at the code in TimerExpiryGoogletestUnitTests.cpp Could you re-use this fixture in other tests for the function ‘how_long_until_next_timer_expiry’?

Demo: Sections for TimerExpiry

Build a test for the IDT timer in both googletest and in catch2.

TEST_F(TimerExpiryTest, IDT_Timer) {
    set_duration_meas_active(timerConfig, true);
    set_duration_meas(timerConfig, 1);
    set_duration_meas_start(timerConfig, now_sec - 1);
    set_last_pkt_time(timerConfig, now_sec);
    set_idt_alarm_time(timerConfig, 3);

    how_long_until_next_timer_expiry(timerConfig, now_sec, &min_value_ms);
    EXPECT_EQ(3000, min_value_ms);
}

SECTION("idt timer")
{
    set_duration_meas_active(timerConfig, true);
    set_duration_meas(timerConfig, 1);
    set_duration_meas_start(timerConfig, now_sec - 1);
    set_last_pkt_time(timerConfig, now_sec);
    set_idt_alarm_time(timerConfig, 3);
    how_long_until_next_timer_expiry(timerConfig, now_sec, &min_value_ms);
    REQUIRE(min_value_ms == 3000);
}

Concrete: create more tests for TimerExpiry

Hand over to them to build more tests in catch2.

Conclusions: review code and compare with sample solution

Conclusions: note most important learning

Note down on a sticky note the most important thing you learnt today