Difference between revisions of "Test CClass Sample"

From STRIDE Wiki
Jump to: navigation, search
(Introduction)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
The Test CClass Samples are part of the [[Test_Unit_Samples|STRIDE Test Unit Samples]].  The CClass naming convention implies a C struct that is acting like a class object for the purpose of test unit development.  The Test CClass Samples pertain to implementing test units in the C language that appear to act like test classes.  If you are using C++, you will want to use the [[Test_Class_Sample|Test Class Samples]] for simplicity.  The Test CClass functionality is predominantly for legacy systems that have not switched over to C++.  However, the Test CClass functionality is not restricted from compiling C++ environment as well (C++ functions must be marked with 'extern "C"' to be used by scl_test_cclass).
+
The Test CClass Samples are part of the [[Test_Unit_Samples|STRIDE Test Unit Samples]].  The CClass naming convention implies a C struct that is acting like a class object for the purpose of test unit development.  The Test CClass Samples pertain to implementing test units in the C language that appear to act like test classes.  If you are using C++, you will want to use the [[Test_Class_Sample|Test Class Samples]] for simplicity.  The Test CClass functionality is predominantly for legacy systems that have not switched over to C++.  However, the Test CClass functionality is not restricted from compiling C++ environment as well.
 
<br><br>
 
<br><br>
 
The following content relates to the sample files and workspaces installed in ''%STRIDE_DIR%\Samples\TestUnits\TestCClass''.  This sample consists of a [http://en.wikipedia.org/wiki/Microsoft_Visual_Studio Visual Studio] workspace for building an [[Windows_Off-Target_Apps| off-target simulator]], sample [[Test Units|scl_test_cclass]] source code, and a STRIDE workspace for doing more advanced test CClass execution.
 
The following content relates to the sample files and workspaces installed in ''%STRIDE_DIR%\Samples\TestUnits\TestCClass''.  This sample consists of a [http://en.wikipedia.org/wiki/Microsoft_Visual_Studio Visual Studio] workspace for building an [[Windows_Off-Target_Apps| off-target simulator]], sample [[Test Units|scl_test_cclass]] source code, and a STRIDE workspace for doing more advanced test CClass execution.

Revision as of 16:06, 1 August 2008

Introduction

The Test CClass Samples are part of the STRIDE Test Unit Samples. The CClass naming convention implies a C struct that is acting like a class object for the purpose of test unit development. The Test CClass Samples pertain to implementing test units in the C language that appear to act like test classes. If you are using C++, you will want to use the Test Class Samples for simplicity. The Test CClass functionality is predominantly for legacy systems that have not switched over to C++. However, the Test CClass functionality is not restricted from compiling C++ environment as well.

The following content relates to the sample files and workspaces installed in %STRIDE_DIR%\Samples\TestUnits\TestCClass. This sample consists of a Visual Studio workspace for building an off-target simulator, sample scl_test_cclass source code, and a STRIDE workspace for doing more advanced test CClass execution.

Getting Started

To begin, open the Visual Studio Solution file in the sample directory. This solution (and corresponding project) were created for Visual Studio 2005. If you have a later version installed, you should be able to open this solution (it will be automatically upgraded if necessary). If you do not have any version of Visual Studio, it is recommended that you install the current free version of Visual Studio Express.

Once you have successfully opened the solution, rebuild it. The build process has custom STRIDE build rules integrated. The rebuilding will produce a STRIDE database, intercept module source files, and an off-target simulator application that incorporates the test class source.

Once the build is complete, perform the following steps to run the test CClasss in the workspace:

  1. launch the off-target simulator, TestCClass.exe. This will run in a standard console window.
  2. open a command prompt window and change to this sample's directory.
  3. at the command prompt, run the command TestUnitRun.pl -v. This will execute all of the test units in the workspace and open a browser to display the results.
  4. quit the TestCClass.exe application by typing 'q' in its console window.

Sample Test CClass

Now that you have built the off-target simulator and executed the test CClasss it contains, you can take time to peruse the test CClass source and the corresponding results that each produces. This section provides a brief description for each.

Basic Examples

These examples cover the simplest, easiest way to code a STRIDE test CClass. These examples use simple POD return types to indicate status and do not annotate the tests with any rich information (such as comments).

01_01_Basic_Simple

Demonstrates passing and failing tests using the four primary POD types that we can infer status from (int, short, and char). The bool POD type is allowed, but only in C++ mode.

01_02_Basic_Fixtures

Shows how to use teardown and teardown fixtures. The setup and teardown methods are called immediately before and after the execution of each test method, respectively.

Runtime Services Examples

These examples cover basic usage of our Runtime Test Services API (as declared in srtest.h).

02_01_RuntimeServices_Simple

Shows how to use srTestCaseSetStatus to set status, srTestCaseAddComment to add a comment, and srTEST_ADD_COMMENT_WITH_LOCATION to add a comment that automatically includes line and file information.

02_02_RuntimeServices_Dynamic

This example is not yet available for scl_test_cclass.

02_03_RuntimeServices_Override

Shows how to use srTestCaseSetStatus to override the status that would otherwise be inferred from the return value.

02_04_RuntimeServices_VarComment

Demonstrates the use of printf style format strings with srTestCaseAddComment.

Test CClass Execution

This sample demonstrates two different techniques for executing test classes.

Commandline Execution

Command line execution for test CClasss is done using the TestUnitRun utility. Here are several examples with specific syntax to execute scl_test_cclass tests. All of these commands can be invoked from a standard command shell and the arguments shown assume that the commands are executed with the sample's directory as the starting directory. You must have your TestCClass.exe application running in order for the runner to be able to initiate a connection to the target simulator. In addition, you should verify that your %STRIDE_DIR%\bin\transport.cfg file is using the TCP transport to connect to port 8000 (these are the default settings when the product is installed).

Simple execution of all test units

The following command executes all of the test units found in the STRIDE database you have previously generated. For the purpose of this sample, since there is only one database, the -d parameter is not strictly needed, but we show it here for completeness.

 TestUnitRun.pl -d TestCClass.sidb

This command executes all Test Units found in the database in descending alpha-numeric sort order. Any Test CClass initialization arguments are given default values (typically zero or NULL).

When you run this command, you should see console output like:

 Attempting connection using [Sockets (S2)] transport ...
 Connected to device.
 Initializing STRIDE database objects...
 Done.
 Running Test CClass_Basic_Fixtures...
 Running Test CClass_Basic_Simple...
 Running Test CClass_RuntimeServices_Override...
 Running Test CClass_RuntimeServices_Simple...
 Running Test CClass_RuntimeServices_VarComment...
 Disconnected from device.
 Test Results saved to C:\s2\seaside\Samples\TestUnits\TestCClass\TestCClass.xml
 Test Report saved to C:\s2\seaside\Samples\TestUnits\TestCClass\TestCClass.html
 ***************************************************************************
 Results Summary
 ***************************************************************************
   Passed:               9
   Failed:               7
   In Progress:          1
   Not Applicable:       1
   ...in 5 suites.
 ***************************************************************************

Execution based on an order file

TestUnitRun can optionally base its execution on simple text file input. We have provided a simple order file, RunSimple.txt, which specifies a subset of all the scl_test_cclass tests in this sample. This order file also shows how to create subsuites in the final output by using the special {suitepath} syntax, as described in the usage section.

 TestUnitRun.pl -d TestCClass.sidb -o RunSimple.txt

...and will produce this output:

 Attempting connection using [Sockets (S2)] transport ...
 Connected to device.
 Initializing STRIDE database objects...
 Done.
 Running Test CClass_Basic_Simple...
 Running Test CClass_RuntimeServices_Simple...
 Disconnected from device.
 Test Results saved to C:\s2\seaside\Samples\TestUnits\TestCClass\TestCClass.xml
 Test Report saved to C:\s2\seaside\Samples\TestUnits\TestCClass\TestCClass.html
 ***************************************************************************
 Results Summary
 ***************************************************************************
   Passed:               7
   Failed:               4
   In Progress:          1
   Not Applicable:       1
   ...in 4 suites.
 ***************************************************************************

Execution based on file system order

TestUnitRun can also try to infer execution order and suite hierarchy from filesystem organization. If you have organized your test CClass source files (only the files that contain the scl_test_CClass pragma matter here) in a filesystem hierarchy that you want to mimic in your tests, you can specify a root of a directory tree that contains the relevant test CClass source. TestUnitRun will walk the directory structure and determine order and hierarchy of tests based on the directory structure. To see an example of this in action, you can execute this command with the sample:

 TestUnitRun.pl -d TestCClass.sidb -f Tests

This will cause the runner to examine the Tests subdirectory structure and build a hierarchy of tests based on that directory tree. Subdirectories will map to suites in the final report. Here is the output for this example:

 Attempting connection using [Sockets (S2)] transport ...
 Connected to device.
 Initializing STRIDE database objects...
 Done.
 Running Test CClass_Basic_Simple...
 Running Test CClass_Basic_Fixtures...
 Running Test CClass_RuntimeServices_Simple...
 Running Test CClass_RuntimeServices_Override...
 Running Test CClass_RuntimeServices_VarComment...
 Disconnected from device.
 Test Results saved to C:\s2\seaside\Samples\TestUnits\TestCClass\TestCClass.xml
 Test Report saved to C:\s2\seaside\Samples\TestUnits\TestCClass\TestCClass.html
 ***************************************************************************
 Results Summary
 ***************************************************************************
   Passed:               9
   Failed:               7
   In Progress:          1
   Not Applicable:       1
   ...in 7 suites.
 ***************************************************************************

Workspace-based Execution

We also provide a sample STRIDE workspace that demonstrates the use of script execution with STRIDE Studio to manage test order and hierarchy. This workspace was created using WorkspaceSetup.pl and the WindowsTestApp framework. The setup and teardown folders provided basic infrastructure scripts that start/stop the simulator application (TestCClass.exe) and to manage traceviews used for srPrint message collection. The scripts that drive the testing are in the workspace test folder. What follows is a brief description for each.

RunAll

This folder contains a single script that iterates through the entire collection of test units and executes them one at a time. The order of execution will be in descending alpabetical order (on name) since we explictly called the ArrangeBy collection method.

Run Individual

This folder shows how to use individual scripts to execute test classes. Each script takes the very simple form:

 ascript.TestUnits.Item(TEST_CClass_NAME).Run();

..where TEST_CClass_NAME is the name of the scl_test_cclass test you want to run. You can then use the Studio tree control to change the order and hierarchy of each item by moving the scripts and creating folders. The sample contains individual scripts for a few of the sample scl_test_cclass tests - you are free to move, add, or delete any items as you experiment with the workspace.