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.
I want 3 reasons to write a test fixture. Make sure they come up with 3 reaons before you proceed.
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’?
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);
}
Hand over to them to build more tests in catch2.
Note down on a sticky note the most important thing you learnt today