2015-06-20 36 views
1

通過Dancer :: Test文檔的閱讀使測試看起來很簡單,但我錯過了一些東西。如果我有以下舞者的應用程序(WebApp.pm):如何運行一個Perl舞者測試

package WebApp; 
use Dancer; 

# declare routes/actions 
get '/' => sub { 
    "Hello World"; 
}; 

dance; 

然後將下面的測試文件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 1.3132 server 7679 listening on http://0.0.0.0:3000 
== Entering the development dance floor ... 

然後等待。 (這與我在WebApp.pm中運行代碼的情況相同)。我在這裏錯過了什麼?我想我沒有正確運行測試。

回答

0

您應該從WebApp.pm中刪除dancer()。這裏是正確的內容:

package WebApp; 
use Dancer; 

# declare routes/actions 
get '/' => sub { 
    "Hello World"; 
}; 

1; 

然後你測試會通過。

常見的方法來創建應用程序舞者是所有路由聲明在一個或多個.pm的文件,並有一個通常被稱爲app.psgi與內容文件:

#!/usr/bin/env perl 
use Dancer; 
use WebApp; 
dance; 

然後開始你的web應用程序你應運行perl -Ilib app.psgi

+0

這工作得很好。謝謝。如果我在WebApp.pm和'Dancer :: set port =>'3003'中使用了'set port => 3003;';''在另一個端口(比默認的3000)測試文件,它繼續工作。 –