--group commandline option should override group/exclude setting in phpunit.xml #322

Closed
sandermarechal opened this Issue Aug 18, 2011 · 5 comments

Comments

Projects
None yet
5 participants

The --group commandline option does not seem to overide the <group><exclude></group> setting. IMHO it should.

Use case: I have a few very slow tests that I put into a single group (@group slow). Normally I do not want to run them, so I put them in the group/exlude tag in phpunit.xml to ignore them. Sometimes I do want to run them, so I type this on the commandline:

phpunit --group slow

I expect PHPUnit to run all the tests in the slow group because commanline options override phpunit.xml options. But in reality, no tests are run. Furthermore, there seems to be no other way to un-exclude a group on the commandline that has been exlcuded in the xml file.

This is exactly how PHPUnit behaves:

➜  test  cat Test.php 
<?php
class Test extends PHPUnit_Framework_TestCase
{
    /**
     * @group one
     */
    public function testOne()
    {
    }

    /**
     * @group two
     */
    public function testTwo()
    {
    }
}


➜  test  cat phpunit.xml 
<phpunit>
 <testsuite name="My Test Suite">
  <file>Test.php</file>
 </testsuite>

 <groups>
  <include>
   <group>one</group>
  </include>
 </groups>
</phpunit>


➜  test  phpunit --debug            
PHPUnit 3.5.15 by Sebastian Bergmann.


Starting test 'Test::testOne'.
.

Time: 0 seconds, Memory: 3.75Mb

OK (1 test, 0 assertions)


➜  test  phpunit --debug --group two
PHPUnit 3.5.15 by Sebastian Bergmann.


Starting test 'Test::testTwo'.
.

Time: 0 seconds, Memory: 3.75Mb

OK (1 test, 0 assertions)

The problem is not with the <groups><include></groups> but with <groups><exclude></groups>. See this (nearly identical) example:

➜  test  cat Test.php 
<?php
class Test extends PHPUnit_Framework_TestCase
{
    /**
     * @group one
     */
    public function testOne()
    {
    }

    /**
     * @group two
     */
    public function testTwo()
    {
    }
}


➜  test  cat phpunit.xml 
<phpunit>
 <testsuite name="My Test Suite">
  <file>Test.php</file>
 </testsuite>

 <groups>
  <exclude>
   <group>one</group>
  </exclude>
 </groups>
</phpunit>

➜  phpunit --debug
PHPUnit 3.5.15 by Sebastian Bergmann.


Starting test 'Test::testTwo'.
.

Time: 0 seconds, Memory: 6.25Mb

OK (1 test, 0 assertions)

➜  phpunit --debug --group one
PHPUnit 3.5.15 by Sebastian Bergmann.



Time: 0 seconds, Memory: 6.00Mb

OK (0 tests, 0 assertions)

On that second command, I expect that testOne is run.

Contributor

edorian commented Nov 10, 2011

Closing as duplicate of #320

@edorian edorian closed this Nov 10, 2011

breerly commented Mar 16, 2012

I've added a workaround on #320

edorian added a commit that referenced this issue Jul 27, 2012

edorian added a commit that referenced this issue Jul 27, 2012

Contributor

andig commented Dec 19, 2013

Reopening here as the issue seems the same:

<groups>
    <exclude>
      <group>slow</group>
    </exclude>
  </groups>

Running a test that contains only slow tests:

C:\data\htdocs\vz\test>phpunit Tests\AggregationPerformanceTest.php --group slow

PHPUnit 3.7.28 by Sebastian Bergmann.
Configuration read from C:\data\htdocs\vz\test\phpunit.xml
Time: 193 ms, Memory: 1.00Mb
No tests executed!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment