Testing and QA

 
 
Picture of Rian Stockbower
phpunit --group annotation
 

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: -
Tim at Lone Pine Koala Sanctuary
Re: phpunit --group annotation
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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 ).

 
Average of ratings: -
Picture of Rian Stockbower
Re: phpunit --group annotation
 

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));
    }
 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: phpunit --group annotation
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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.

 
Average of ratings: -
Picture of Rian Stockbower
Re: phpunit --group annotation
 

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.

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: phpunit --group annotation
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Yes, but what happens when you run

phpunit --group Link2Wiki

or

phpunit --group CompanyExtensions

 
Average of ratings: -
Picture of Rian Stockbower
Re: phpunit --group annotation
 

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)
 
Average of ratings: -
Dan at desk in Moodle HQ, Perth
Re: phpunit --group annotation
Group DevelopersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

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

 
Average of ratings: -