1*dd6c3661SShawn McCarney## Overview 2*dd6c3661SShawn McCarney 3*dd6c3661SShawn McCarneyThe [test](../test) directory contains automated test cases written using the 4*dd6c3661SShawn McCarney[GoogleTest](https://github.com/google/googletest) framework. These tests are 5*dd6c3661SShawn McCarneyrun during Continuous Integration (CI) testing. 6*dd6c3661SShawn McCarney 7*dd6c3661SShawn McCarneyThe goal is to write automated test cases for as much application code as 8*dd6c3661SShawn McCarneypossible. 9*dd6c3661SShawn McCarney 10*dd6c3661SShawn McCarney## Test case conventions 11*dd6c3661SShawn McCarney 12*dd6c3661SShawn McCarneyEach implementation source file should have a corresponding tests file. For 13*dd6c3661SShawn McCarneyexample, [rail.cpp](../src/rail.cpp) is tested by 14*dd6c3661SShawn McCarney[rail_tests.cpp](../test/rail_tests.cpp). 15*dd6c3661SShawn McCarney 16*dd6c3661SShawn McCarneyWithin the tests file, there should be a TEST for each public method or global 17*dd6c3661SShawn McCarneyscope function. For example, `Rail::isPresent()` is tested by 18*dd6c3661SShawn McCarney`TEST(RailTests, IsPresent)`. 19*dd6c3661SShawn McCarney 20*dd6c3661SShawn McCarney## Mock framework 21*dd6c3661SShawn McCarney 22*dd6c3661SShawn McCarneyOne of the primary challenges with automated testing is handling external 23*dd6c3661SShawn McCarneyinterfaces. The phosphor-power-sequencer application depends on the following 24*dd6c3661SShawn McCarneyexternal interfaces: 25*dd6c3661SShawn McCarney 26*dd6c3661SShawn McCarney- D-Bus 27*dd6c3661SShawn McCarney- Journal 28*dd6c3661SShawn McCarney- Error logging 29*dd6c3661SShawn McCarney- GPIOs 30*dd6c3661SShawn McCarney- sysfs files containing PMBus information 31*dd6c3661SShawn McCarney- BMC dump 32*dd6c3661SShawn McCarney 33*dd6c3661SShawn McCarneyThese interfaces are either not available or do not behave properly within the 34*dd6c3661SShawn McCarneyCI test environment. Thus, in automated test cases they need to be mocked. 35*dd6c3661SShawn McCarney 36*dd6c3661SShawn McCarneyThe GoogleTest mock framework is used to implement mocking. This allows the 37*dd6c3661SShawn McCarneybehavior of the external interface to be simulated and controlled within the 38*dd6c3661SShawn McCarneytest case. 39*dd6c3661SShawn McCarney 40*dd6c3661SShawn McCarneyThe mock framework typically relies on a class hierarchy of the following form: 41*dd6c3661SShawn McCarney 42*dd6c3661SShawn McCarney- Abstract base class with virtual methods for external interfaces 43*dd6c3661SShawn McCarney - Concrete sub-class with real implementation of virtual methods that call 44*dd6c3661SShawn McCarney actual external interfaces 45*dd6c3661SShawn McCarney - Mock sub-class that provides mock implementation of virtual methods 46*dd6c3661SShawn McCarney 47*dd6c3661SShawn McCarneyThe phosphor-power-sequencer application follows this pattern using the 48*dd6c3661SShawn McCarneyfollowing classes: 49*dd6c3661SShawn McCarney 50*dd6c3661SShawn McCarney- [Services](../src/services.hpp) 51*dd6c3661SShawn McCarney - [BMCServices](../src/services.hpp) 52*dd6c3661SShawn McCarney - [MockServices](../test/mock_services.hpp) 53