如何运行Perl Dancer测试
通读Dancer::Test文档使测试看起来很简单,但我遗漏了一些东西。如果我有以下Dancer应用程序(如何运行Perl Dancer测试,perl,testing,dancer,Perl,Testing,Dancer,通读Dancer::Test文档使测试看起来很简单,但我遗漏了一些东西。如果我有以下Dancer应用程序(WebApp.pm): 然后是以下测试文件001_base.t: use strict; use warnings; use Test::More tests => 1; use WebApp; use Dancer::Test; response_status_is [GET => '/'], 200, "GET / is found"; 然后,当我运行测试:perl 0
WebApp.pm
):
然后是以下测试文件001_base.t
:
use strict;
use warnings;
use Test::More tests => 1;
use WebApp;
use Dancer::Test;
response_status_is [GET => '/'], 200, "GET / is found";
然后,当我运行测试:perl 001_base.t
时,输出是dancer脚本启动:
Dancer 1.3132 server 7679 listening on http://0.0.0.0:3000
== Entering the development dance floor ...
然后等待。(这与我只是在WebApp.pm中运行代码相同)。我错过了什么?我想我没有正确运行测试 您应该从WebApp.pm中删除
dancer()
。以下是正确的内容:
package WebApp;
use Dancer;
# declare routes/actions
get '/' => sub {
"Hello World";
};
1;
那么你的考试就会通过
创建dancer应用程序的常用方法是在一个或多个.pm文件中声明所有路由,并创建一个名为app.psgi
的文件,其中包含以下内容:
#!/usr/bin/env perl
use Dancer;
use WebApp;
dance;
然后,要启动web应用程序,应该运行
perl-Ilib app.psgi
,这非常有效。谢谢我还试图让它在不同的端口下工作(默认3000端口除外),如果我使用set port=>3003和Dancer::set port=>3003'代码>在测试文件中,它继续工作。
#!/usr/bin/env perl
use Dancer;
use WebApp;
dance;