Studio:Scripting Test Units: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Scripting a Test Unit ==
== Scripting a Test Unit ==
In most [[Test Units|Test Unit]] applications, a standard, S2-supplied host test runner is sufficient. However, for applications that require finer control, Test Units may be run from custom-written scripts.
In most [[Test Units|Test Unit]] applications, a standard, S2-supplied host test runner is sufficient. However, for applications that require finer control, Test Units may be run from custom-written scripts.
This capability is offered by the [[STRIDE Studio]] product.


Custom scripts can be written by hand or automatically generated using the Script Wizard and a corresponding [[Templates|template script]]. These scripts use the [[AutoScript]] (Ascript) COM object to access test metadata and features of the STRIDE Runtime. Specifically, the [[AutoScript#ascript.TestUnits|AutoScript TestUnits]] collection is used to represent the currently-available [[Test Units]]. The collection comprises [[AutoScript#ascript.TestUnits.Item|Ascript TestUnit]] objects which represent the individual Test Units.  
Custom scripts can be written by hand or automatically generated using the Script Wizard and a corresponding [[Templates|template script]]. These scripts use the [[AutoScript]] (Ascript) COM object to access test metadata and features of the STRIDE Runtime. Specifically, the [[AutoScript#ascript.TestUnits|AutoScript TestUnits]] collection is used to represent the currently-available [[Test Units]]. The collection comprises [[AutoScript#ascript.TestUnits.Item|Ascript TestUnit]] objects which represent the individual Test Units.  
Line 66: Line 68:
</source>
</source>


[[Category:Scripting]]
[[Category:Studio:Scripting]]
[[Category:Test Units]]
[[Category:Studio:Test Units]]

Latest revision as of 00:37, 21 August 2009

Scripting a Test Unit

In most Test Unit applications, a standard, S2-supplied host test runner is sufficient. However, for applications that require finer control, Test Units may be run from custom-written scripts.

This capability is offered by the STRIDE Studio product.

Custom scripts can be written by hand or automatically generated using the Script Wizard and a corresponding template script. These scripts use the AutoScript (Ascript) COM object to access test metadata and features of the STRIDE Runtime. Specifically, the AutoScript TestUnits collection is used to represent the currently-available Test Units. The collection comprises Ascript TestUnit objects which represent the individual Test Units.

Scripting your Test Unit runner gives you the following extra capabilities:

  • You can pass values to C++ Class Test Unit constructors
  • You can programmatically control which test units run and their order
  • You can customize reporting options through the Reporter object

Single test unit example

The following example script is used to harness a test unit that has been captured using #pragma scl_test_class(Simple).

JavaScript

var tu = ascript.TestUnits.Item("Simple");
// Ensure test unit exists
if (tu != null) 
  tu.Run();

Perl

use strict;
use Win32::OLE;
Win32::OLE->Option(Warn => 3);
   
my $tu = $main::ascript->TestUnits->Item("Simple");
if (defined $tu) {
  $tu->Run();
}

Multiple test units example

The following example script is used to harness two test units that have been captured using #pragma scl_test_class(Simple1) and #pragma scl_test_class(Simple2).

JavaScript

var Units = ["Simple1","Simple2"];
  
// iterate through each function
for (i in Units)
{
  var tu = ascript.TestUnits.Item(Units[i]);
  if ( tu != null ) 
    tu.Run();
}

Perl

use strict;
use Win32::OLE;
Win32::OLE->Option(Warn => 3);
   
# initialize an array with all selected function names
my @UnitNames = ("Simple1","Simple2");
foreach (@UnitNames) {   
  my $tu = $main::ascript->TestUnits->Item($_->[1]);
  die "TestUnit not found: $_->[1]\n" unless (defined $tu);
  $tu->Run();
}