Difference between revisions of "Test Fixturing in C/C++"

From STRIDE Wiki
Jump to: navigation, search
(Created page with '== What is Test Fixturing? == Recall that generic xUnit testing comprises four discrete phases: # Setup # Exercise # Verify # Teardown ''Test fixturing'' refers to the Setup…')
 
 
Line 40: Line 40:
  
 
STRIDE  offers an integrated solution to file fixturing  that makes it possible  from your target test code to specify a  host-based file and transfer its  data to the target. Refer to the [[File_Services_Samples  | File  Services  Samples]] that demonstrates techniques and  syntax for performing basic tasks using the [[File  Transfer  Services|File Transfer Services API]].
 
STRIDE  offers an integrated solution to file fixturing  that makes it possible  from your target test code to specify a  host-based file and transfer its  data to the target. Refer to the [[File_Services_Samples  | File  Services  Samples]] that demonstrates techniques and  syntax for performing basic tasks using the [[File  Transfer  Services|File Transfer Services API]].
 +
 +
[[Category: Test Units]]

Latest revision as of 16:40, 28 May 2010

What is Test Fixturing?

Recall that generic xUnit testing comprises four discrete phases:

  1. Setup
  2. Exercise
  3. Verify
  4. Teardown

Test fixturing refers to the Setup and Teardown phases of the testing.

In the Setup phase, we put all of the things into place that are required in order to run a our test and expect a particular outcome. This includes things like:

  • Acquiring resources such as memory, hardware, etc.
  • Setting up required states such as input files in place, memory filled with a pattern, dependencies initialized, etc.

In the Tear down phase, we clean up the fixturing we did in the Setup phase, leaving the system in a state that is ready to be used by the next test.

The Importance of Fixturing

The proper use of fixturing can simplify test writing and lead to these benefits:

  • Separation of initialization/deinitialization code from your test code
  • Reuse of setup and teardown code within a test unit
  • Simplification of resource cleanup in test methods

STRIDE Fixturing Resources

Specifying Fixturing Methods

Within your source code, you can optionally specify setup and teardown methods using the scl pragmas:

When declaring these pragmas, you specify 1) the test unit the pragma applies to; and 2) the name of the method that will be called by the STRIDE framework to perform the Setup or Teardown fixturing. If specifed, the STRIDE framework will call the Setup method before each test method in the test unit, and the Teardown method after each test method in the test unit.

You can see examples of fixturing delcarations in these test samples:

Advanced Fixturing

A common test pattern--especially in the area of multimedia--is to create a test that is parametrized by an input file. The test is run multiple times with a different input file used for each run.

In this case the setup fixturing makes the file data available to the test (typically opening a file on the host, then copying data from host to target), and the teardown fixturing removes any files created on the target and so forth.

STRIDE offers an integrated solution to file fixturing that makes it possible from your target test code to specify a host-based file and transfer its data to the target. Refer to the File Services Samples that demonstrates techniques and syntax for performing basic tasks using the File Transfer Services API.