Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate Unit and Functional Tests in Symfony2?

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?

like image 854
Koryonik Avatar asked Dec 20 '13 09:12

Koryonik


1 Answers

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.

like image 102
Dovydas Bartkevičius Avatar answered Sep 28 '22 08:09

Dovydas Bartkevičius