phpunit --group annotation

phpunit --group annotation

by Rian Stockbower -
Number of replies: 7

I've written a filter, and some unit tests to go with it. I can run the tests when I specify the specific class, but I can't choose to run the test group it belongs to.

I've essentially just put an @group GroupName at the top of my PHP test file. As I develop more plugins, I'd like to be able to run them by GroupName:

/**
 * Unit tests for the FooBar filter
 * @group InhouseExtensions
 */

Running --list-groups gives me a bunch of authors(?), and that's about it.

If I had to guess, I'd say it probably has something to do with not defining a testsuite in phpunit.xml.dist. That probably means I should create a second XML config file, but that's really just a guess.

Has someone gotten the --group annotation going? If so, how did you do it?

Average of ratings: -
In reply to Rian Stockbower

Re: phpunit --group annotation

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You need to put the annotation on the testcase class. It works for qtype_stack (e.g. https://github.com/maths/moodle-qtype_stack/blob/master/tests/question_test.php ).

In reply to Tim Hunt

Re: phpunit --group annotation

by Rian Stockbower -

Yes, I've done that already:

/**
 * Unit tests for Link2Wiki filter
 * @group CompanyExtensions
 */

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot . '/filter/Link2Wiki/filter.php');

class filter_Link2Wiki_test extends basic_testcase {

    /**
     * @dataProvider buildWikiUrlDataProvider
     */
    public function test_buildWikiUrl($articleName, $linkText, $expected) {
        $this->assertEquals($expected, filter_Link2Wiki::buildWikiUrl($articleName, $linkText));
    }
In reply to Rian Stockbower

Re: phpunit --group annotation

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

No, you have not done that. You have put a PHPdoc comment at the start of the .php file. You have not put a PHPdoc comment immediately before the class statement.

In reply to Tim Hunt

Re: phpunit --group annotation

by Rian Stockbower -

OK, I've done that:

<?php

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot . '/filter/Link2Wiki/filter.php');

/**
 * Unit tests for Link2Wiki filter
 * @group CompanyExtensions
 * @group Link2Wiki
 */
class filter_Link2Wiki_test extends basic_testcase {

    /**
     * @dataProvider buildWikiUrlDataProvider
     */
    public function test_buildWikiUrl($articleName, $linkText, $expected) {
        //...
    } //...

Then I ran init.php again. This is the output of --list-groups:

Available test group(s):
 - Andrew Nicols
 - Charles Severance csev@unmich.edu
 - Chris Scribner
 - David Jimenez
 - Jordi Piguillem
 - Josep Arus
 - Kenneth Riba
 - Marc Alier
 - Marc Alier (marc.alier@upc.edu)
 - Mark Nielsen
 - Nikolas Galanis
 - Petr Skoda {@link http://skodak.org}
 - Sam Marshall
 - T.J.Hunt@open.ac.uk
 - Yuliya Bozhko <yuliya.bozhko@totaralms.com>
 - __nogroup__
 - core_plugin
 - nicolas@moodle.com

We are running 2.5 right now, if that matters.

In reply to Rian Stockbower

Re: phpunit --group annotation

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, but what happens when you run

phpunit --group Link2Wiki

or

phpunit --group CompanyExtensions

In reply to Tim Hunt

Re: phpunit --group annotation

by Rian Stockbower -

Nothing.

 

$ phpu --group Link2Wiki
Moodle 2.5 (Build: 20130514), mysqli
PHPUnit 3.7.24 by Sebastian Bergmann.

Configuration read from /var/www/html/moodle/phpunit.xml



Time: 0 ms, Memory: 197.50Mb

No tests executed!
vadev@rianjsmoodle: /var/www/html/moodle
$ phpu --group CompanyExtensions
Moodle 2.5 (Build: 20130514), mysqli
PHPUnit 3.7.24 by Sebastian Bergmann.

Configuration read from /var/www/html/moodle/phpunit.xml



Time: 0 ms, Memory: 198.00Mb

By contrast:

$ phpu filter_Link2Vistawiki_test ./filter/Link2Wiki/tests/filter_test.php
Moodle 2.5 (Build: 20130514), mysqli
PHPUnit 3.7.24 by Sebastian Bergmann.

Configuration read from /var/www/html/moodle/phpunit.xml

.........

Time: 1.81 seconds, Memory: 56.50Mb

OK (9 tests, 9 assertions)
In reply to Rian Stockbower

Re: phpunit --group annotation

by Dan Poltawski -

Not really answering your question, but another approach (if you name your classes prefixed by your component name) is to use --filter.

phpunit --filter local_mycustomisation