Test Double Sample

From STRIDE Wiki
Revision as of 17:34, 4 June 2009 by Mikee (talk | contribs)
Jump to navigation Jump to search

Introduction

Please read the Using Test Doubles article before proceeding in order to understand the concepts. You also review the information available here for more details on test double terminology.

Tests Description

Basic

Basic::TestFunction

This example uses a C++ test class to validate the test_func1 function under test. The dependency depend1 is left in place during the CallNoDoubling method. The dependency is replaced with a fake method, which simply returns a constant in the CallWithFake method. The dependency is replaced with a mock method, which validates the passed in parameter, in the CallWithMock method.
The intercept mangling parameters in this example, in the scl_function pragma, uses the "DEFINITION" option to indicate the the intercept will be at the function definition, and the"IMPLICIT" option because no mangling is required to intercept (because the caller and callee are in separate compilation units).

Basic::TestFunctionWithDepend

This example uses a C++ test class to validate the test_func2 function under test. The dependency depend2 is left in place during the CallNoDoubling method. The dependency is replaced with a fake method, which simply returns a constant in the CallWithFake method. The dependency is replaced with a mock method, which validates the passed in parameter, in the CallWithMock method.
The intercept mangling parameters in this example, in the scl_function pragma, uses the "REFERENCE" option to indicate the the intercept will be at the function call, and the"EXPLICIT" option because mangling is required to intercept (because the caller and callee reside in the same source file).