PHP Unit Tests: should tests be under the same namespace as the class?

Viewed 4507

The Symfony 2.0 bundle directory structure, conventionally, has a Tests directory where tests should be placed.

Acme
    -> SomeBundle
        -> Controller
        -> Entity
        -> Service
        -> ...
        -> Tests
            -> Controller
            -> Entity
            -> Service
            -> ...
    -> OtherBundle
    -> ...

I am aware the tests work even if they are not under the same namespace as the classes they test.

namespace Acme\SomeBundle\Service;

/**
 * Some service.
 *
 * @author varchar
 * @since  August 1, 2012
 */
class SomeService
{
}

For the class above, I (for one) would usually have a test under the following name space (as influenced by the directory structure):

namespace Acme\SomeBundle\Tests\Service;

Now, this works okay.

Incidentally however, I use the Netbeans IDE which cannot find a test class unless it is under the same namespace (this is notable when you want to test only a single file). Well, this could be just a Netbeans standard (or something).

Regardless however, is it appropriate to put tests under the same namespace as the class being tested? Are there any merits in doing so?

Question

1) Is it appropriate to put tests under the same namespace as the class being tested?

2) Are there any merits in doing so?

2 Answers
Related