Studio:Pretesting Test Script: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
If a target binary is not available when developing tests, create a target emulator. | |||
A target emulator will allow you to create more correct and accurate tests, and allow you to view and tune your output reports. | |||
In most cases, the best approach is to create one or more scripts that implement the owner side of the interfaces that are being tested. Emulator scripts are then launched asynchronously to run concurrently with the test scripts. An example of this is shown in the article [[How to synchronize scripts]]. | |||
An effective means of starting and stopping these scripts is by creating special emulator starter and stopper scripts that run before and after your test scripts. | |||
== Example Target Emulator Launcher == | |||
<source lang="perl> | |||
use strict; | |||
use warnings; | |||
use Carp; | |||
use Win32::OLE; | |||
Win32::OLE->Option(Warn => 3); | |||
# emulator script is in a folder named 'scriptTarget' | |||
use constant EMULATOR_SCRIPT_LOGICAL_PATH => 'Script Files/scriptTarget/myTargetEmulator.pl'; | |||
my $targetScript = $main::studio->Workspace->Files->Item(EMULATOR_SCRIPT_LOGICAL_PATH); | |||
my $scriptName = $targetScript->Name; | |||
if (!$targetScript->IsRunning) { | |||
$targetScript->RunNonBlocking(); | |||
$main::studio->Output->PrintMessage("Target Emulator started: $scriptName"); | |||
} | |||
else { | |||
$main::studio->Output->PrintMessage("Target Emulator already running: $scriptName"); | |||
} | |||
</source> | |||
== Example Target Emulator Stopper == | |||
<source lang="perl"> | |||
use strict; | |||
use warnings; | |||
use Carp; | |||
use Win32::OLE; | |||
# emulator script is in a folder named 'scriptTarget' | |||
use constant EMULATOR_SCRIPT_LOGICAL_PATH => 'Script Files/scriptTarget/myTargetEmulator.pl'; | |||
## Stop the target emulator by broadcasting message | |||
$main::ascript->Messages->Item("_BRD_SCRIPTSYNC_EXITLOOP")->Owner->Broadcast(); | |||
# wait for target to exit | |||
my $target = $main::studio->Workspace->Files->Item(EMULATOR_SCRIPT_LOGICAL_PATH); | |||
my $countdown = 5; | |||
while ($target->IsRunning && $countdown) { | |||
sleep(1); | |||
$countdown--; | |||
} | |||
# and close window | |||
$target->Close(); | |||
</source> | |||
[[Category:Script Writing]] | [[Category:Script Writing]] | ||
[[Category:Practice]] | [[Category:Practice]] |
Revision as of 00:46, 10 December 2008
If a target binary is not available when developing tests, create a target emulator.
A target emulator will allow you to create more correct and accurate tests, and allow you to view and tune your output reports.
In most cases, the best approach is to create one or more scripts that implement the owner side of the interfaces that are being tested. Emulator scripts are then launched asynchronously to run concurrently with the test scripts. An example of this is shown in the article How to synchronize scripts.
An effective means of starting and stopping these scripts is by creating special emulator starter and stopper scripts that run before and after your test scripts.
Example Target Emulator Launcher
use strict;
use warnings;
use Carp;
use Win32::OLE;
Win32::OLE->Option(Warn => 3);
# emulator script is in a folder named 'scriptTarget'
use constant EMULATOR_SCRIPT_LOGICAL_PATH => 'Script Files/scriptTarget/myTargetEmulator.pl';
my $targetScript = $main::studio->Workspace->Files->Item(EMULATOR_SCRIPT_LOGICAL_PATH);
my $scriptName = $targetScript->Name;
if (!$targetScript->IsRunning) {
$targetScript->RunNonBlocking();
$main::studio->Output->PrintMessage("Target Emulator started: $scriptName");
}
else {
$main::studio->Output->PrintMessage("Target Emulator already running: $scriptName");
}
Example Target Emulator Stopper
use strict;
use warnings;
use Carp;
use Win32::OLE;
# emulator script is in a folder named 'scriptTarget'
use constant EMULATOR_SCRIPT_LOGICAL_PATH => 'Script Files/scriptTarget/myTargetEmulator.pl';
## Stop the target emulator by broadcasting message
$main::ascript->Messages->Item("_BRD_SCRIPTSYNC_EXITLOOP")->Owner->Broadcast();
# wait for target to exit
my $target = $main::studio->Workspace->Files->Item(EMULATOR_SCRIPT_LOGICAL_PATH);
my $countdown = 5;
while ($target->IsRunning && $countdown) {
sleep(1);
$countdown--;
}
# and close window
$target->Close();