How do I get code coverage of Perl CGI script when executed by Selenium?

孤街浪徒 提交于 2019-12-10 17:16:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!