开发者

Which Perl test module should I use?

开发者 https://www.devze.com 2023-01-15 23:14 出处:网络
There\'s Test::Simple, Test::More, Test::Builder (all part of the Test::开发者_JAVA百科Simple distribution), Test::Class, Test::Unit, Test::Moose...

There's Test::Simple, Test::More, Test::Builder (all part of the Test::开发者_JAVA百科Simple distribution), Test::Class, Test::Unit, Test::Moose...

I'm starting a new project using Moose—which module should I use for writing my tests?


You can eliminate Test::Builder from the list for a while. Test::Builder is the base module that other Test:: modules are built on. So until you want to start writing your own test modules you won't need it.

I'd also ignore Test::Simple. Test::More does all that Test::Simple does - and plenty more.

Test::Class is a nice way to write unit tests in a really object oriented way. I'd recommend it for complex OO-based systems.

Test::Moose is for testing various Moose-related features in your code. You say that you're using Moose so it might well be useful for you. It can be used in conjunction with Test::More.

So my recommendation would be to start with Test::More and Test::Moose. But also take a look at Test::Class to see if it fits with the way that you want to write tests.

Perl Testing: A Developers Notebook is a great introduction to this topic.


In addition to davorg's excellent answer, I'd like to note that I'm still mostly using Test::More (with some help from Test-Differences, Test-WWW-Mechanize-LibXML, and other modules). I can recommend against using Test.pm which is old and stupid, and Test::Simple, which is a small subset of the Test::More functionality.

There are also Test::Most (an extension of Test::More), Test::Class and Test::Class::Most, which some people prefer, but I didn't take the time to learn them yet.

There's an ongoing debate about whether a plan (= tests' count) is a good thing or not. Personally, I've already noticed a case in someone else's CPAN module where the count of tests was different on my system's than on them (and varied based on different versions of DBI (IIRC)) and which convinced me that the plan is a good thing. As a result I've created Test-Count which is a way to count and update the assertions count based on annotations inside well-formed comments (and which supports source code in other languages besides Perl 5). I'm still supporting it, so if you need anything, give me a shout.


I'd recommend Test::Class as a basis for your test framework. It makes for better structured, more modular code. And you can still use Test::More and other Test modules with it. Also check Test::Exception.


Others have suggested Test::Class; I have found the following PDF overview from $foo Magazin (I didn't write it, just found it) was quite helpful for some exampled beyond what the POD documentation provides.


It is not really essential for moose development. However, if you're into Web Development , I think Test::WWW::Selenium is becoming indespensable for testing javascript-heavy web pages and their behavior in the most common web browsers (firefox, iexplorer, googlechrome, etc.)

0

精彩评论

暂无评论...
验证码 换一张
取 消