Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the preferred unit testing framework for Perl?

I'm sort of new to Perl and I'm wondering if there a prefered unit testing framework?

Google is showing me some nice results, but since I'm new to this, I don't know if there is a clear preference within the community.

like image 824
Mike Avatar asked May 20 '10 17:05

Mike


People also ask

Which framework is used for unit testing?

Jest was the most popular JavaScript unit testing framework in 2020. For web apps that are based on React, Jest is the preferred framework. Apart from React, Jest supports unit testing of Angular, VueJS, NodeJS, and others.

How do I write a unit test case in Perl?

use strict; use warnings; use Test::More; package Foo { do 'script_one.pl'; }; is Foo::print_name, 'foo', 'prints the right name'; This way you can mock dependencies more easily and you get some more control.

Which Selenium framework is mostly used?

One of the most popular frameworks for Selenium web driver with the data-driven feature is TestNG. This framework is most commonly used in supply chain and financial industry, where data is a very crucial aspect of operations. Pros: Test data is maintained separately, so it is easy to make changes in the test script.


1 Answers

Perl has a MASSIVE set of great testing tools that come with it! The Perl core has several tens of thousands of automated checks for it, and for the most part they all use use these standard Perl frameworks. They're all tied together using TAP - the Test Anything Protocol.

The standard way of creating TAP tests in Perl is using the Test::More family of packages, including Test::Simple for getting started. Here's a quick example:

use 5.012; use warnings;  use Test::More tests => 3;  my $foo = 5; my $bar = 6;  ok $foo == 5, 'Foo was assigned 5.'; ok $bar == 6, 'Bar was assigned 6.'; ok $foo + $bar == 11, 'Addition works correctly.'; 

And the output would be:

ok 1 - Foo was assigned 5. ok 2 - Bar was assigned 6. ok 3 - Addition works correctly. 

Essentially, to get started, all you need to do is put pass a boolean value and a string explaining what should occur!

Once you get past that step, Test::More has a large number of other functions to make testing other things easier (string, regex compares, deep structure compares) and there's the Test::Harness back end that will let you test large groups of individual test scripts together.

On top of that, as Schwern pointed out, almost all of the modern Test:: modules work together. That means you can use Test::Class (as pointed out by Markus) with all of the great modules listed in rjh's answer. In fact, because Test::Builder--the tool that Test::More and others are built on (and currently maintained by Schwern...thanks Schwern!)--you can, if needed, build your OWN test subroutines from the ground up that will work with all the other test frameworks. That alone makes Perl's TAP system one of the nicest out there in my opinion: everything works together, everyone uses the same tool, and you can add on to the framework to suit your needs with very little additional work.

like image 135
Robert P Avatar answered Oct 12 '22 23:10

Robert P