Difference between revisions of "Test Units Overview"

From STRIDE Wiki
Jump to: navigation, search
Line 16: Line 16:
 
# Set the workspace to cpp mode (for compilation).
 
# Set the workspace to cpp mode (for compilation).
 
# Add {STRIDE_DIR}\inc\srtest.h to the Source Files folder of your workspace.
 
# Add {STRIDE_DIR}\inc\srtest.h to the Source Files folder of your workspace.
# Add {STRIDE_DIR}\scripts\TestClasses\TestClass_Preprocess.pl (or .js) to your Script Files folder.  If you will be adding a script to compile the workspace (see next step), this script must always '''preceed''' the compilation step.
+
# Add {STRIDE_DIR}\scripts\TestClasses\TestClass_Preprocess.pl (or .js) to your Script Files folder.  This script is a preprocessor and code generator.  It searches all source files in the current workspace and looks for test classes that have been captured via the ''scl_test_class'' pragma. It then generates c-linkage wrapper functions that instantiate and execute each test class.  By default, this generated source file has a name of the form {WORKSPACE_NAME}TCR.cpp and will be located in the workspace directory. If you need to change the name and/or location of this generated file, simply set the '''outFile''' property of the STRIDE.testclass_codegen object prior to calling the generate method.  If you will be adding a script to compile the workspace (see next step), this preprocessing script must always '''preceed''' the compilation step.
 
# Add a script to compile the workspace.  In it's simplest form, this script can simple be something like:
 
# Add a script to compile the workspace.  In it's simplest form, this script can simple be something like:
 
   #perl syntax
 
   #perl syntax
 
   Win32::OLE->Option(Warn => 3);
 
   Win32::OLE->Option(Warn => 3);
 
   $main::studio->Workspace->Compile();
 
   $main::studio->Workspace->Compile();
or
+
 
   /* jscript syntax */
+
   // jscript syntax
 
   studio.Workspace.Compile();
 
   studio.Workspace.Compile();
 
+
# Add a script to generate the Intercept Module(IM).  For the simple STUB generation required for C++ test class execution, you can use {STRIDE_DIR}\scripts\TestClasses\TestClass_Preprocess.pl (or .js) for this purpose.
#
+
# Add scripts to build and execute your application.  If you are using a host based simulator, we examples available of both. If you are using actual devices, the steps required for building and starting the application are specific to the target environment.
 +
# Create one or more test classes to implement your C++ test logic.  See below for more information on creating test classes.
 +
# Ensure that the Studio workspace include path has the location to all of your test class declaration (header) files.
 +
# Once you have created one or more test classes, save the workspace and run the scripts, starting with the TestClass_Preprocess script, followed by compile, IM generation and application building.

Revision as of 22:37, 19 June 2007

Introduction

STRIDE enables testing of C++ code through the use of xUnit style test classes. Test classes can be written by engineers, captured using an SCL pragma, and executed from the host. STRIDE facilitates the execution of some or all of the test classes by automatically creating entry points for the execution of test classes on the target.

Using CPP Test Classes

Prerequisites

The CPP Test class support only works in the 2.0.0802 version of STRIDE or later. The host PC must also have a recent distribution of ActiveState perl installed.

How to get started

The following is an outline of the required steps to get started with writing C++ test classes.

  1. Create a new Studio workspace (or open an existing one).
  2. Set the workspace to cpp mode (for compilation).
  3. Add {STRIDE_DIR}\inc\srtest.h to the Source Files folder of your workspace.
  4. Add {STRIDE_DIR}\scripts\TestClasses\TestClass_Preprocess.pl (or .js) to your Script Files folder. This script is a preprocessor and code generator. It searches all source files in the current workspace and looks for test classes that have been captured via the scl_test_class pragma. It then generates c-linkage wrapper functions that instantiate and execute each test class. By default, this generated source file has a name of the form {WORKSPACE_NAME}TCR.cpp and will be located in the workspace directory. If you need to change the name and/or location of this generated file, simply set the outFile property of the STRIDE.testclass_codegen object prior to calling the generate method. If you will be adding a script to compile the workspace (see next step), this preprocessing script must always preceed the compilation step.
  5. Add a script to compile the workspace. In it's simplest form, this script can simple be something like:
 #perl syntax
 Win32::OLE->Option(Warn => 3);
 $main::studio->Workspace->Compile();
 // jscript syntax
 studio.Workspace.Compile();
  1. Add a script to generate the Intercept Module(IM). For the simple STUB generation required for C++ test class execution, you can use {STRIDE_DIR}\scripts\TestClasses\TestClass_Preprocess.pl (or .js) for this purpose.
  2. Add scripts to build and execute your application. If you are using a host based simulator, we examples available of both. If you are using actual devices, the steps required for building and starting the application are specific to the target environment.
  3. Create one or more test classes to implement your C++ test logic. See below for more information on creating test classes.
  4. Ensure that the Studio workspace include path has the location to all of your test class declaration (header) files.
  5. Once you have created one or more test classes, save the workspace and run the scripts, starting with the TestClass_Preprocess script, followed by compile, IM generation and application building.