9

I wonder :

  1. if it's a good idea to separate tests (Unit | Functional ...) in Symfony2,
  2. and how I should separate:

By folders structure :

tests 
|-- functional    
|-- unit

By config in phpunit.xml :

<testsuites>
    <testsuite name="unit">...</testsuite>
    <testsuite name="functional">...</testsuite>
</testsuites>

By annotation

/**
 * @group unit    
 */
 function testMyUnit()

Ii it a reasonable approach? Is there a standard way to do this? What "levels" separate (unit > integration > functional)? And how to take advantage of that if I want to play with these tests manually and fastest, and obtain rational coverage reports in Jenkins?

2
  • What's wrong with the standard approach of putting your functional tests in the Controller folder of your bundle? Commented Dec 23, 2013 at 12:24
  • Where put integration tests (using kernel, or container for example) or "functional code" out of controller ? Commented Dec 23, 2013 at 12:35

1 Answer 1

9

You can go for two configuration files - one for functional and one for unit tests. Then you can run your unit tests separately from functional. You want your unit tests to run as quickly as possible or otherwise nobody's gonna run them at development time, so this approach works quite well.

phpunit -c app/phpunit.xml
phpunit -c app/phpunit_functional.xml

The directory structures we used:

src/Namespace/Bundle/Tests/Unit/
src/Namespace/Bundle/Tests/Functional/

The second way is to have one configuration file and run phpunit --testsuite unit.

Sign up to request clarification or add additional context in comments.

1 Comment

how does this work across multiple bundles? do i have to update a global phpunit file every time I add/remove a bundle?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.