Test::UniqueTestNames - Make sure all of your tests have unique names


Version 0.04


For scripts that have no plan:

  use Test::UniqueTestNames;

that's it, you don't need to do anything else.

For scripts that have a plan, like this:

  use Test::More tests => x;

change to

  use Test::More tests => x + 1;
  use Test::UniqueTestNames;


Test names are useful in assessing the contents of a test file. They're also useful in debugging. And when a test breaks, it's much easier to figure out what test broke if the test names are unique. This module checks the names of every test to make sure that they're all unique. If there are any tests that have duplicate names, it wil give a "not ok" and diagnostics of which test names have been used for multiple tests.

Test names aren't required by most testing modules, but by default Test::UniqueTestNames counts tests without names as failures. You can change that behavior by importing unnamed_ok.

Specifically, this module is useful in the situation where tests are run in a loop, such as these:

  for( @fixture_data ) {
    my( $input, $output ) = @$_;

    ok( Some::Class->method( $input ), "...and the method works"; # test name will be the same each time

    is( Some::Class->method( $input ), $output, "...and the method works with $input"; # names could be the same
                                                                                       # if there is a duplicate in $input

This test is similar in most respects to Test::NoWarnings.


Some tests generate their own test names, and thus shouldn't be counted as failures when they have non-unique test names. This currently only applies to Test::More's isa_ok.



This checks to see that all tests had unique names. Usually you will not call this explicitly as it is called automatically when your script finishes.


Josh Heumann, <cpan at>


Using with Test::Exception

This module currently throws a warning when used with Test::Exception. This is due to a bug in Hook::LexWrap, and a patch has been submitted to correct the problem.

Please report any bugs or feature requests to bug-test-uniquetestnames at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.




Copyright 2008 Josh Heumann, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.