This method strips the leading section of the package name, up to and including the first ::, and returns the rest of the name as the name of the class being tested. For example, if your test class is named Tests::Some::Person, the name Some::Person is returned as the name of the class to use and test. If your test class is named IHateTestingThis::Person, then Person is the name of the class to be used and tested.

If you don't like how the name is calculated, you can override this method in your code.

Warning: Don't use Test:: as a prefix. There are already plenty of modules in that namespace and you could accidentally cause a collision.

First, if you need to rename your class, you must change this name repeatedly. With Test::Class::Moose::Role::AutoUse, you only rename the test class name to correspond to the new class name and you're done.

The first problem is not very serious, but the second problem is. Let's say you have a Person class and then you create a Person::Employee subclass. Your test subclass might look like this:

Object-oriented tests inherit their parent class tests. Thus, TestsFor::Person::Employee will inherit the TestsFor::Person->test_constructor() method. Except as you can see in our example above, we've hardcoded the class name, meaning that we won't be testing our code appropriately. The code using the Test::Class::Moose::Role::AutoUse role doesn't hardcode the class name (at least, it shouldn't), so when we call the inherited TestsFor::Person::Employee->test_constructor() method, it constructs a TestsFor::Person::Employee object, not a TestsFor::Person object.

Some might argue that this is a strawman and we should have done this:

Yes, that's correct. We should have done this, except that now it's almost identical to the AutoUse code, except that the first time you forget to use the class in question, you'll be unhappy. Why not automate this?