The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Test::Tdd::Generator - Generate tests for existing code

SYNOPSIS

Add those lines inside the function you want to generate a test for:

    use Test::Tdd::Generator;
    Test::Tdd::Generator::create_test('<test description>');

If you also need some globals you can include them like this:

    use Test::Tdd::Generator;
    Test::Tdd::Generator::create_test('<test description>', { globals => ['Example::'] });

This will generate a test like this

                it '<test description>' => sub {
                                my $input = Test::Tdd::Generator::load_input(dirname(__FILE__) . "/input/MyModule_does_something.dump");
                                Test::Tdd::Generator::expand_globals($input->{globals});

                                my $result = MyModule::untested_subroutine(@{$input->{args}});

                                is($result, "fixme");
                };

Methods

PACKAGE::create_test($test_description [, $opts])

Creates a test on the closest t/ folder, saving the original inputs that the function received as well. You can also save globals you might need passing them on $opts, check the example above

PACKAGE::load_input($dump_file)

Evaluates a dump file to load the inputs on the test to be able to call the function

PACKAGE::expand_globals($globals)

Expand globals that were exported to run the tests