2

PHPUnit manual say:

If you point the PHPUnit command-line test runner to a directory it will look for *Test.php files.

see: http://www.phpunit.de/manual/3.6/en/organizing-tests.html#organizing-tests.filesystem

This is wrong!

When i call:

phpunit --config myconfig.xml --bootstrap mybootstrap.php tests

It takes all php files.

  1. First idea was to use blacklist or whitelist in the config xml, but then i realised, that these lists are filters for subject under tests and filters test classes.
  2. Second thought was to use testsuites within the config xml. But at the moment the test suites can be defined only, but not executed via command line (not jet implemented in PHPUnit, ticket is open for more than 1 year).
  3. Next thought was to use a test suite loader, but i can not find a documentation on how to use them and if a tsl is what i think it is.

When i run:

phpunit --config myconfig.xml --bootstrap mybootstrap.php --loader My_Testsuite_Loader tests

PHPUnit takes all php file in "tests/" and executes them. The file "My/Testsuite/Loader.php" will be included. PHPUnit checks if the class My_Testsuite_Loader exists. All fine so far.

I used the "PHPUnit/Runner/StandardTestSuiteLoader.php" as template for "My/Testsuite/Loader.php". It contains the methods "load()" and "reload()". Both methods are never called by the PHPUnit Framework. Why not? I thought to have a own testsuiteloder will give me the oportunity to implement a test suite exclude schema.

Sample file system of my project:

<root>
|-src/MyProject/Package/Object.php
|-tests/MyProject/Package/Object/TestTemplate.php
|-tests/MyProject/Package/Object/GetFooTest.php
|-tests/MyProject/Package/Object/GetBarTest.php
|-tests/phpunit.xml
|-tests/bootstrap.php
|-tests/My/Testsuite/Loader.php

As you can see i use one file for all tests about a sut (method under test). All these *Test.php files inherits from TestTemplate (TestCase). In TestTemplate.php is a setup which initializes the object (Object.php) and stores it in a private member var.

How to use the test suite loader / for what is it meant to be? (How to exclude test classes that do not fit to the pattern: "*Test.php"?)

Tunaki
  • 132,869
  • 46
  • 340
  • 423
user1182585
  • 75
  • 1
  • 6
  • 1
    Firstly, there is no such flag as `--config`, it is either `-c` or `--configuration`. Secondly, You don't have to provide neither a bootstrap file nor the test suite loader, if You're already providing a configuration file, all can be set there. Thirdly, You don't even have to provide a configuration file, as long as it's called `phpunit.xml` or `phpunit.xml.dist` and You call the `phpunit` script from the right directory. Fourthly, the documentation is correct about what You think is wrong. And finally, i think the problem might be in your configuration file. Could You show what's in there? – zafarkhaja May 08 '12 at 09:23
  • @zafarkhaja: you are right about --config. You can override xml settings by using command line switches, and this can make sense if you try to integrate phpunit into an IDE (different run configurations, but a shared xml). – DanielaWaranie Jun 29 '13 at 00:09
  • @DanielaWaranie, yes, indeed. In those cases it makes sense. Thank you. – zafarkhaja Jun 29 '13 at 16:26

1 Answers1

-1

You need to take out the 'tests' argument like so

phpunit --config myconfig.xml --bootstrap mybootstrap.php

Then in your myconfig.xml

<testsuites>
   <testsuite name="AllTests">
      <directory>.</directory>
   </testsuite>
<testsuites>

<filter>
  <blacklist>
    <directory suffix=".xml">.</directory>
    <file>MyProject/Package/Object/TestTemplate.php</file>
  </blacklist>
</filter>
Josh Woodcock
  • 2,683
  • 1
  • 22
  • 29