What's the difference between test suite and test group? If I want to organize my unit tests in phpunit.xml
in groups of tests (i.e. groups of directiories), e.g. tests for specific application module.
- How should the
phpunit.xml
look like to utilize groups and test suites?
- How to run specific group/test suite from the command line?
Similar question:
- PHPUnit - Running a particular test suite via the command line test runner
PHPUnit manual about test suites and groups in xml configuration:
- http://www.phpunit.de/manual/3.4/en/appendixes.configuration.html
- http://www.phpunit.de/manual/current/en/organizing-tests.html
How to configure the groups in phpunit.xml
, that phpunit --list-groups
showed them?
Test suites organize related test cases whereas test groups are tags applied to test methods.
Using the @group
annotation you can mark individual test methods with descriptive tags such as fixes-bug-472
or facebook-api
. When running tests you can specify which group(s) to run (or not) either in phpunit.xml
or on the command line.
We don't bother with test suites here, but they can be useful if you need common setup and teardown across multiple tests. We achieve that with a few test case base classes (normal, controller, and view).
We aren't using groups yet, either, but I can already think of a great use for them. Some of our unit tests rely on external systems such as the Facebook API. We mock the service for normal testing, but for integration testing we want to run against the real service. We could attach a group to the integration test methods to be skipped on the continuous integration server.