kinow / testopia-plugin

Jenkins plug-in to integrate different test management tools
2 stars 6 forks source link

Support for template to wrap testcase script in Test framework harness #16

Closed tooh closed 11 years ago

tooh commented 11 years ago

Don't know how this is handled in Testlink plugin. This is what I did in my perl prototype.

The retrieving of testcase is now done by the plugin, so process is much simpler now.

if ($Outputpath) {
my $result = $soapresult->result;

foreach my $testcase (@{$result}) {
my $outfile ="$Outputpath$testcase->{alias}.t";
print "outfile : $outfile\n";
    open TC , ">$Outputpath$testcase->{alias}.t";
        print TC "#!/usr/bin/perl\n";
        print TC "=head1 NAME" . "\n\n";
        print TC "$testcase->{alias}" . "\n\n";
        print TC "=head1 DESCRIPTION" . "\n\n";
        print TC "$testcase->{summary}" . "\n\n";
                print TC "=head1  REQUIREMENT(S)" . "\n\n";
        print TC "$testcase->{requirement}" . "\n\n";
                print TC "=head1 TESTCASES" . "\n\n";
        print TC "Case ID : $testcase->{case_id}" . "\n\n";
        print TC "=head1 AUTHOR" . "\n\n";
        print TC "$Bugzilla_login" ."\n\n";
        print TC "=head1 DATE GENERATED" . "\n\n";
        print TC "$now" . "\n\n";
        print TC "=cut" . "\n\n";

        print TC "use Test::More;\n";
        print TC "# OSX reports 'darwin' as OS\n";
        print TC "if( \$^O ne 'darwin' ) {\n";
            print TC  "\tplan skip_all => 'Test only relevant on MacOS';\n";
        print TC  "}\n";
        print TC  "else {\n";
            print TC  "\tplan tests => 1;\n";
        print TC  "}\n";
        print TC  "#\n";
        print TC  "# variables from Testopia\n";
        print TC  "#\n";
        print TC  "\$case_id = $testcase->{case_id};" ."\n";
        print TC  "#\n";
        print TC  "# variables passed from prove\n";
        print TC  "#\n";
        print TC  "\$testrun_id = \$ARGV[0];" . "\n";
        print TC  "\$build_id = \$ARGV[1];" . "\n";
        print TC  "\$env_id = \$ARGV[2];" . "\n";
        print TC  "print \"Case ID\t: \$case_id \\n\"; \n"; 
        print TC  "print \"Build ID\t: \$build_id \\n\"; \n"; 
        print TC  "print \"Env ID\t: \$env_id \\n\"; \n"; 
        print TC  "#\n";
        print TC  "# Script to run as entered in the Testopia test case\n";
        print TC  "#\n";
#       print TC  "exec => ['/usr/bin/perl', '$testcase->{script} $testcase->{arguments}']" ."\n";
        print TC "\$result=`$testcase->{script} $testcase->{arguments}`;\n";
        print TC  "diag explain \$result;\n";
        print TC  "#\n";
        print TC  "# Determine result of script\n";
        print TC  "#\n";
        print TC  "\$exit_code = (\$? >> 8);\n";
        print TC  "ok(\$exit_code == 0,'$testcase->{alias} - $testcase->{summary} ');\n";
        print TC  "#\n";
        print TC  "# update the status of the testcase run" . "\n";
        print TC  "#\n";
        print TC  "if (\$exit_code == 0) {" ."\n";
        print TC  "\t \$passed = 2;" ."\n";
        print TC  "}" . "\n";
        print TC  "else {" ."\n";
        print TC  "\t \$passed = 3;" . "\n";
        print TC  "}" ."\n";
        print TC  "# Update Testopia status only if part of run" . "\n";
        print TC  "\$update=`./updtestopia.sh \$testrun_id \$case_id \$build_id \$env_id \$passed`;\n";
        print TC  "print \"\$update \\n \";\n";

                print TC "done_testing(1);\n";
    close TEST;
        }

}
kinow commented 11 years ago

Issue ported to JIRA, see issues.jenkins-ci.org