Training Advanced

From STRIDE Wiki
Revision as of 15:49, 6 July 2015 by Marku (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 Unit. The following functions will be used to demonstrate fixturing:

void sut_start_thread(void);
void sut_stop_thread(void);

Example option file my.opt used below for running

 --database "%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb"
 --device TCP:localhost:8000

Test Doubles

This Test Unit focuses on leveraging Test Doubles in the context of executing a test.

The following articles are related to this example:

The Test Unit 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 Test Unit. Start the TestApp.exe and use the following command:

 stride --options_file my.opt --run "TestDoubles"

You can take a look at the results by opening the generated stride.html in your browser.

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 Unit focuses on Test Points and how to validate them.

The following articles are related to this example:

The Test Unit 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 Test Unit. Start the TestApp.exe and use the following command:

 stride --options_file my.opt --run "TestPoints"

You can take a look at the results by opening the generated stride.html in your browser.

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 Unit focuses on using Fixutures in the context of an executing Test Unit.

The Test Unit 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 Test Unit. Start the TestApp.exe and use the following command:

 stride --options_file my.opt --run "TestFixtures"

You can take a look at the results by opening the generated stride.html in your browser.

Consider the following for TryStuff:

  • Write a test to validate "A", "B", and "C" using the "TRIGGER"