2011-11-29 26 views
6

Ben Catalyst::Controller::REST kullanarak, bir sığınakta web hizmeti inşa ediyorum sınamak için en kolay yolu nedir. Genellikle web testi için Test::WWW::Mechanize kullanıyorum, ancak "GET/POST HTML RPC" testi için daha uygun görünüyor. GET/POST/PUT/DELETE vb ve JSON kullanarak, temel auth ile HTTP testini yapacak herhangi bir Test modülleri var mı? Belki de Catalyst/PSGI ile iyi entegre olan bir şey var, bu yüzden bir web sunucusu başlatmak zorunda değil miyim?Bir Katalizör DİNLENME API

cevap

7

Katalizör :: Test LWP :: UserAgent bir alt sınıfıdır. Aşağıda size doğru bir fikir vermelidir:

#!/usr/bin/env perl 
use warnings; 
use strict; 

use Test::More; 
use Catalyst::Test 'MyApp'; 
use HTTP::Request::Common; 
use JSON::Any; # or whatever json module you usually use 
my $data = 'some_json_data_here'; 
my $res = request(
    POST '/some_path', 
    Content_Type => 'text/xml', 
    Content => $data, 
); 

my $content = json_decode($res->content); # or whatever, can't remember the interface. 
my $expected = "some_data"; 
is_deeply ($content, $expected); 
+0

çalışacağız, ancak ben, sadece tüm JSON/HTTP kod yazmadan benim için seri hale getirme/deserialization yapacağı bir şey yoktu mesela kolaylık yöntemleri umuyordum . – xenoterracide

İlgili konular