Difference between revisions of "Test Double Sample"

From STRIDE Wiki
Jump to: navigation, search
(Tests Description)
(Basic::TestFunction)
Line 10: Line 10:
 
===Basic::TestFunction===
 
===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.<br>
+
This case validate <tt>test_func1</tt> function (implemented in s2_testdouble_function.h/c) which in turn depends on <tt>depend1</tt> function (in s2_testdouble_depend.h/c).  
The intercept mangling parameters in this example, in the [[Using Test Doubles#Configuring_the_Double_Using_SCL|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).
+
 
 +
Using a [[Using Test Doubles#Configuring_the_Double_Using_SCL|scl_function]] pragma the dependency is intercepted (in s2_testdouble_depend_scl.h). The '''"DEFINITION"''' option indicates that the intercept will be at the function definition, and the '''"IMPLICIT"''' option that no mangling is required to intercept (the caller and callee are in separate compilation units).
 +
 
 +
;CallNoDoubling
 +
: Simple case to demonstrate operation where no doubling is used. The true <tt>depend1</tt> is used when testing <tt>test_func1</tt>.
 +
 
 +
;CallWithFake
 +
: Dynamically replaces dependency <tt>depend1</tt> with a fake <tt>fake_depend_1</tt> function, which simply returns a constant.
 +
 
 +
;CallWithMock
 +
: Dynamically replaces dependency <tt>depend1</tt> with a mock <tt>mock_depend_1</tt> function, which validates the passed in parameter and proceeds as the original <tt>depend1</tt>.
  
 
===Basic::TestFunctionWithDepend===
 
===Basic::TestFunctionWithDepend===

Revision as of 17:07, 9 June 2010

Introduction

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

This example presents two different function double settings that differ in the point of interception (at DEFINITION vs. at REFERENCE).

Tests Description

Basic::TestFunction

This case validate test_func1 function (implemented in s2_testdouble_function.h/c) which in turn depends on depend1 function (in s2_testdouble_depend.h/c).

Using a scl_function pragma the dependency is intercepted (in s2_testdouble_depend_scl.h). The "DEFINITION" option indicates that the intercept will be at the function definition, and the "IMPLICIT" option that no mangling is required to intercept (the caller and callee are in separate compilation units).

CallNoDoubling
Simple case to demonstrate operation where no doubling is used. The true depend1 is used when testing test_func1.
CallWithFake
Dynamically replaces dependency depend1 with a fake fake_depend_1 function, which simply returns a constant.
CallWithMock
Dynamically replaces dependency depend1 with a mock mock_depend_1 function, which validates the passed in parameter and proceeds as the original depend1.

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).