Difference between revisions of "Parameterized Test Units"

From STRIDE Wiki
Jump to: navigation, search
(Created page with 'You can leverage the tests you write in Test Units by using STRIDE's parameterization feature. This allows you to supply parameters to your test units at run time to customize te…')
 
Line 1: Line 1:
 
You can leverage the tests you write in Test Units by using STRIDE's parameterization feature. This allows you to supply parameters to your test units at run time to customize test behavior.
 
You can leverage the tests you write in Test Units by using STRIDE's parameterization feature. This allows you to supply parameters to your test units at run time to customize test behavior.
 +
 +
==How Parameters are Passed from the Host==
 +
Parameters to be passed to a target test unit are supplied on the stride.exe command line used to invoke the test unit. Test unit parameter values are specified between parentheses characters immediately following the test unit name on the command line.
 +
 +
===Number Parameter===
 +
For example, assume that you have a test unit implemented on the target named MyTest and it has been coded to accept a single integer parameter. To run this test unit with the parameter value 17, use the following run specification:
 +
 +
<pre>
 +
--run=MyTest(17)
 +
</pre>
 +
 +
===String Parameter===
 +
As a second example, consider a test unit coded to take a single string as a parameter. The parameter is supplied as follows:
 +
 +
<pre>
 +
--run=MyOtherTest(\"string\")
 +
</pre>
 +
 +
Note that the string parameter must be enclosed with double quote characters. The double quotes are escaped with a backslash as this is required by the command line processor.
 +
 +
====Parameter Containing Spaces====
 +
 +
When the string parameter contains one or more spaces, the command processor further requires you to enclose the entire <tt>--run</tt> argument in double quotes as follows:
 +
 +
<pre>
 +
--run="MyOtherTest(\"this is the parameter\")"
 +
</pre>
 +
 +
Note that the command line processor requires you to enclose with double quotes if there are any spaces at all in the <tt>--run</tt> argument. This can be counter-intuitive when passing only number types.
 +
 +
;No space in argument list
 +
<pre>
 +
--run=TestX(123,555,3.14)
 +
</pre>
 +
 +
;Space in argument list
 +
<pre>
 +
--run="TestX(123, 555, 3.14)"
 +
</pre>
 +
 +
===Multiple Parameters===
 +
You may pass any number of parameters to a test unit, and each parameter may be of any supported type. An example is shown below:
 +
 +
<pre>
 +
--run="YetAnotherTest(19.58, -1, \"Encinitas\", 92024, \"south\")"
 +
</pre>
 +
 +
A few additional examples are shown on the STRIDE Test Runner [[STRIDE_Runner#Test_Unit_Specification_Examples | Reference page]].
 +
 +
 +
==How Parameters are Received on the Target==
 +
Parameters are passed from the stride.exe command line and are presented on the target
 +
 +
; cpp test unit
 +
Parameters are presented as constructor arguments to the test unit class
 +
 +
; c-class test unit
 +
initialization parameters to a c-class test unit. (
 +
 +
; flist test unit
 +
: Not supported
  
 
==Parameter Types==
 
==Parameter Types==
Line 17: Line 78:
 
|}
 
|}
  
==How Parameters are Passed from the Host==
 
 
==How Parameters are Received on the Target==
 
Parameters are passed from the stride.exe command line and are presented on the target
 
 
; cpp test unit
 
Parameters are presented as constructor arguments to the test unit class
 
  
; c-class test unit
 
initialization parameters to a c-class test unit. (
 
  
; flist test unit
+
[[Category: Test Units]]
: Not supported
 

Revision as of 12:35, 27 June 2011

You can leverage the tests you write in Test Units by using STRIDE's parameterization feature. This allows you to supply parameters to your test units at run time to customize test behavior.

How Parameters are Passed from the Host

Parameters to be passed to a target test unit are supplied on the stride.exe command line used to invoke the test unit. Test unit parameter values are specified between parentheses characters immediately following the test unit name on the command line.

Number Parameter

For example, assume that you have a test unit implemented on the target named MyTest and it has been coded to accept a single integer parameter. To run this test unit with the parameter value 17, use the following run specification:

 --run=MyTest(17)

String Parameter

As a second example, consider a test unit coded to take a single string as a parameter. The parameter is supplied as follows:

 --run=MyOtherTest(\"string\")

Note that the string parameter must be enclosed with double quote characters. The double quotes are escaped with a backslash as this is required by the command line processor.

Parameter Containing Spaces

When the string parameter contains one or more spaces, the command processor further requires you to enclose the entire --run argument in double quotes as follows:

 --run="MyOtherTest(\"this is the parameter\")"

Note that the command line processor requires you to enclose with double quotes if there are any spaces at all in the --run argument. This can be counter-intuitive when passing only number types.

No space in argument list
 --run=TestX(123,555,3.14)
Space in argument list
 --run="TestX(123, 555, 3.14)"

Multiple Parameters

You may pass any number of parameters to a test unit, and each parameter may be of any supported type. An example is shown below:

 --run="YetAnotherTest(19.58, -1, \"Encinitas\", 92024, \"south\")"

A few additional examples are shown on the STRIDE Test Runner Reference page.


How Parameters are Received on the Target

Parameters are passed from the stride.exe command line and are presented on the target

cpp test unit

Parameters are presented as constructor arguments to the test unit class

c-class test unit

initialization parameters to a c-class test unit. (

flist test unit
Not supported

Parameter Types

ANSI strings and number parameter types are directly supported.

String types
  • char*
  • const char*
Number types
  • all integer types
  • float
  • double