Difference between revisions of "Test Double Sample"

From STRIDE Wiki
Jump to: navigation, search
Line 1: Line 1:
 +
==Introduction==
 +
 +
Please read the [[Using Test Doubles]] article before proceeding in order to understand the concepts. You also review the information available [http://xunitpatterns.com/Mocks,%20Fakes,%20Stubs%20and%20Dummies.html here] for more details on test double terminology.
  
 
==Tests Description==
 
==Tests Description==
 
'''''Note:''''' It is recommended that you read the [[Using Test Doubles]] article before proceeding in order to understand the concepts.
 
  
 
=== Basic ===
 
=== Basic ===
  
====Test Function====
+
====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 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>
 
The intercept mangling parameters in this example, in the [[Function_Double#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).
 
The intercept mangling parameters in this example, in the [[Function_Double#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).
  
====Test Function With Depend====
+
====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.<br>
 
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.<br>
 
The intercept mangling parameters in this example, in the [[Function_Double#Configuring_the_Double_Using_SCL|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).
 
The intercept mangling parameters in this example, in the [[Function_Double#Configuring_the_Double_Using_SCL|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).

Revision as of 11:34, 4 June 2009

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