tree: 4fb05ce04927e6f7d11b31ac7e83a14abc31299d [path history] [tgz]
  1. Makefile.in
  2. README.md
  3. config.h.in
  4. configure
  5. configure.ac
  6. inc/
  7. src/
agent/test/README.md

OpenOLT Agent Unit Test

OpenOLT agent unit test framework is based on the following frameworks

The goal of the unit tests for OpenOLT agent is to test is to test the OpenOLT application by stubbing and mocking the external interfaces, especially the BAL API and GRPC.

Building and Running Unit Test

Follow the below steps to build and run unit test

$ cd agent/test
# Run Autoconfig to generate the appropriate makefile scaffolding for the desired target
./configure
# This will build pre-requisite software to build openolt. Needed once only.
$ make prereq
# This will install gtest and c-mock libraries. Needed once only
$ make prereq-mock-lib
# This will build and run the unit test cases
$ make test

Once you have successfully built and run the unit-test, the test report will be available in test_openolt_report.xml file in agent/test. To clean all build artificats and test reports, do make clean in agent/test.

Adding new Unit Test Cases

Before you add new test cases please read GOOGLE TEST COOKBOOK and USING CMOCK to get acquainted with frameworks used for the unit-test cases.

Create mocks, if needed

Refer agent/test/src/bal_mocker.cc and agent/test/src/bal_mocker.h to see how mock functions are created (if needed by your test case). In the afore mentioned examples, mocks are created for certain BAL APIs.

Create Unit Test Case

Please refer example agent/test/src/test_enable_olt.cc. Tests are grouped under Test Fixtures, i.e., TEST_F which takes argument of Test Fixture Name and the Test Case. There will typically be many test cases under a test fixture. Also it is preferrable to create a new file for different test fixtures. If your test case needs mocking, you will need to instantiate the appropriate mocker class you have created and use the ON_CALL, EXPECT_CALL or other utilities from the gtest suite to produce the required behavior. Use the ASSERT_XXX utility from the gtest suite to verify the required result. Please refer the GOOGLE TEST COOKBOOK for detailed documentation.