Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the good frameworks for unit-testing and mock objects in Perl?

What frameworks and tools would you recommend for unit-testing and mock objects in Perl?

I have an existing Perl application, that mainly does database access, reading and writing files. The application is basically a batch job type of application, it reads in bunch of stuff from files and database and writes a bunch of new files and some stuff to database.

The application currently does not have any unit-test, but I'd like refactor application to have good unit tests.

What frameworks and tools would you recommend for unit-testing and mocking objects? For example something similar to Hamcrest and JMock of Java?

Also, are there any good BDD (Behaviour Driven Development) based testing frameworks for Perl?

like image 422
Juha Syrjälä Avatar asked Oct 05 '09 09:10

Juha Syrjälä


People also ask

Which framework is used for unit testing?

JUnit is an open source framework you can use to write and run tests. It aims to help develop bug-free and reliable code written in Java. JUnit provides test runners that run tests and assertions to test the expected results.

Which framework is used to create mocked objects?

We can use Mockito class mock() method to create a mock object of a given class or interface. This is the simplest way to mock an object. We are using JUnit 5 to write test cases in conjunction with Mockito to mock objects.

What are mocking frameworks?

What is a mocking framework? Mocking frameworks are used to generate replacement objects like Stubs and Mocks. Mocking frameworks complement unit testing frameworks by isolating dependencies but are not substitutes for unit testing frameworks.


1 Answers

In terms of test frameworks, I like to use Test::Class, which lets you set up nice unit test hierarchies in a manner similar to JUnit. The linked documentation gives a pretty good overview, though if you're not already familiar with Perl testing conventions, check out the documentation for Test::Simple and TAP, which is the standard output format for Perl tests.

For mocking, there is Test::Mock::Class, which is useful for setting up mock classes for libraries outside your direct control, like CPAN modules that your application relies on.

There is also the excellent Test::MockDBI which provides special facilities for mocking your database stuff.

like image 104
friedo Avatar answered Oct 20 '22 16:10

friedo