问题
I'm using Eclipse EPIC IDE to write some Perl CGI scripts which call some Perl modules that I have also written. The EPIC IDE lets me configure a Perl CGI "run configuration" which runs my CGI script. And then I've got Selenium set up and one of my unit test files runs some Selenium commands to run my cgi script through its paces. But the coverage report from Module::Build dispatch 'testcover' doesn't show that any of my module code has been executed. It's been executed by my cgi script, but I guess the CGI script was run manually and was not executed directly by my unit test file, so maybe that's why the coverage isn't being recognized. Is there a way to do this right so I can integrate Selenium and unit test files and code coverage all together somehow?
回答1:
I'm not familiar with Selenium or EPIC, but one workaround (unless/until someone comes with more native solution) is to simply include "-MDevel::Cover" into the run configuration command line.
Worse comes to worst, add some conditional logic in BEGIN{} block that - based on some selenium environment variable - conditionally does use Devel::Cover
UPDATE:
It should be possible to suppress output from Devel::Cover using -MDevel::Cover=-silent,1
$ perl5.8 -MDevel::Cover -e '{1;}'
Devel::Cover 0.64: Collecting coverage data for branch, blah
Selecting packages matching:
Ignoring packages matching:
blah, blah, blah
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
Total n/a n/a n/a n/a n/a n/a n/a
---------------------------- ------ ------ ------ ------ ------ ------ ------
$ perl5.8 -MDevel::Cover=-silent,1 -e '{1;}'
$
来源:https://stackoverflow.com/questions/2901293/how-do-i-get-code-coverage-of-perl-cgi-script-when-executed-by-selenium