Training Advanced
The Advanced training focuses on using Test Doubles, Test Points, and Fixtures.
The Test Doubles will demonstrate how global functions can be dynamically intercepted and replaced with test logic (stub, fake, mock). The following functions contained in software_under_test will be used to demonstrate how to leverage interception when testing:
int sut_foo(int x); int sut_boo(int x); int sut_2xboo(int x); int sut_strcheck(const char *s);
Test Points enable a different style of testing using source instrumentation. This is especially applicable when normal API testing is not practical. The following sequencing functions will be called that issue Test Points. Note that the sequencing routines are very simple, keeping the focus on the technique that can be applied.
void sut_Sequence1(void); void sut_Sequence2(void); void sut_Sequence3(void);
Fixturing shows how setup and teardown routines per test method can be incorporated within a Test Suite. The following functions will be used to demonstrate fixturing:
void sut_start_thread(void); void sut_stop_thread(void);
Test Doubles
This test suite focuses on leveraging Test Doubles in the context of executing a test.
The following articles are related to this example:
- Using Test Doubles
- Definition verses Reference
- Explicit verses Implicit
- Setting and Resetting the Double implementation
- How to apply pragmas for function intercepting
The Test Suite is called TestDoubles and is implemented in two source files: testdoubles.cpp and testdoubles.h. The comments and descriptions are contained in the header file. Three test cases (methods) are already implemented and one test method that can be used to make changes to is called TryStuff. Currently the TryStuff test method is set to not in use.
First thing to do is run the TestDoubles Suite. Start the TestApp.exe and use the following command:
stride --options_file my.opt --run "TestDoubles"
You can take a look at the results in TestApp.xml.
Consider the following for TryStuff:
- Create your own stub for foo() and intercept it
- confirm it returns what you expect
- Double sut_boo()
- call sut_2xboo() with a number
- confirm within the test double (using a Test Macro) the expected passed in number (mocking example)
Test Points
This test suite focuses on Test Points and how to validate them.
The following articles are related to this example:
- Presentation of a validation technique based on code sequencing and state data
- Overview of source instrumentation
- Review of expectation tables and predicates
- Test Point Macro definition
The Test Suite is called TestPoints and is implemented in two source files: testpoints.cpp and testpoints.h. The comments and descriptions are contained in the header file. Three test cases (methods) are already implemented and one test method that can be used to make changes to is called TryStuff. Currently the TryStuff test method is set to not in use.
First thing to do is run the TestPoints Suite. Start the TestApp.exe and use the following command:
stride --options_file my.opt --run "TestPoints"
You can take a look at the results in TestApp.xml.
Consider the following for TryStuff:
- Write a test to validate a subset of Test Points
- Write a test to validate "E", "F", and "G", and a predicate to verify data associated with "E"
Fixtures
This test suite focuses on using Fixutures in the context of an executing Test Suite.
The following articles are related to this example:
The Test Suite is called TestFixtures and is implemented in two source files: testfixtures.cpp and testfixtures.h. The comments and descriptions are contained in the header file. One test cases (methods) is already implemented and one test method that can be used to make changes to is called TryStuff. Currently the TryStuff test method is set to not in use.
First thing to do is run the TestFixtures Suite. Start the TestApp.exe and use the following command:
stride --options_file my.opt --run "TestFixtures"
You can take a look at the results in TestApp.xml.
Consider the following for TryStuff:
- TBD
- TBD