Project

General

Profile

Feature #5568

Add @assert tags to functions

Added by Yannick Warnier over 6 years ago. Updated almost 3 years ago.

Status:
Needs testing
Priority:
Normal
Assignee:
-
Category:
Global / Others / Misc
Target version:
Start date:
01/10/2012
Due date:
% Done:

90%

Estimated time:
200.00 h
Spent time:
Complexity:
Normal
SCRUM pts - complexity:
?

Description

In order to generate unit tests, we can either generate them by hand or be intelligent and use a tests framework that will generate them for us.

This can be done with phpunit-skelgen but it requires adding a few lines of documentation to the functions or methods we want to test.

As an example, I've added the following two lines at the end of the PHP docblock in main/inc/lib/usermanager.lib.php::create_user():

          * @assert ('Sam','Gamegie',5,'sam@example.com','jo','jo') > 1
          * @assert ('Pippin','Took',null,null,'jo','jo') === false

This revealed, by the way, that there is no immediate check on the definition of an e-mail or a status at the beginning of create_user() (already making progress and we didn't even start this yet!)

To generate your test class for one single class like UserManager (although this should be part of a more structured script to generate them all at once):
phpunit-skelgen --test -- UserManager /var/www/chamilo19x/main/inc/lib/usermanager.lib.php UserManagerTest /tmp/test/UserManagerTest.php

where:
  • UserManager is the name of the class
  • /var/www/chamilo19x is my directory for Chamilo 1.9.x
  • UserManagerTest is the name of the test class to be generated
  • /tmp/test/UserManagerTest.php is the destination file for the test class

Even if @assert tags have not been set, the script will still generate the test method, but without any test, like this:

    /**
     * @covers UserManager::can_delete_user
     * @todo   Implement testCan_delete_user().
     */
    public function testCan_delete_user()
    {
        // Remove the following lines when you implement this test.
        $this->markTestIncomplete(
          'This test has not been implemented yet.'
        );
    }

This is a long-lasting task, so leaving it without specific version (although the sooner, the better).

Current simpletest-based tests in the tests/ directory of Chamilo could be removed (most of them are useless now as they were generated by non-experts and have almost not been updated since 3 years ago). I would launch a new directory called tests/phpunit/ and put everything in there.

Associated revisions

Revision 0f3c892a (diff)
Added by Julio Montoya about 9 years ago

Fixes #5568 requires testing

Revision 06df7ba6 (diff)
Added by Julio Montoya about 9 years ago

Fixes #5568 showing the user extra field and user tag when exporting or showing information in Reporting

Revision b0c14ae5 (diff)
Added by Yannick Warnier over 6 years ago

Adding default test classes for phpunit + generator script - refs #5568

History

#1

Updated by Yannick Warnier about 6 years ago

  • Target version set to 1.9.6
#2

Updated by Yannick Warnier almost 6 years ago

  • Target version changed from 1.9.6 to 2.0

Ongoing task

#3

Updated by Anonymous almost 6 years ago

  • Status changed from New to Needs testing
  • % Done changed from 0 to 90

Applied in changeset gitlocal|commit:0f3c892a40453cc0cbda154b3757b873692b6a37.

#4

Updated by Anonymous almost 6 years ago

Applied in changeset gitlocal|commit:06df7ba6da6dc549f1e6df30660bd6f7180c9690.

#5

Updated by Anonymous over 4 years ago

Applied in changeset githubclone|commit:0f3c892a40453cc0cbda154b3757b873692b6a37.

#6

Updated by Anonymous over 4 years ago

Applied in changeset githubclone|commit:06df7ba6da6dc549f1e6df30660bd6f7180c9690.

#7

Updated by Anonymous about 4 years ago

Applied in changeset github|commit:0f3c892a40453cc0cbda154b3757b873692b6a37.

#8

Updated by Anonymous about 4 years ago

Applied in changeset github|commit:06df7ba6da6dc549f1e6df30660bd6f7180c9690.

#9

Updated by Anonymous almost 4 years ago

Applied in changeset chamilo-lms|commit:0f3c892a40453cc0cbda154b3757b873692b6a37.

#10

Updated by Anonymous almost 4 years ago

Applied in changeset chamilo-lms|commit:06df7ba6da6dc549f1e6df30660bd6f7180c9690.

#11

Updated by Yannick Warnier almost 3 years ago

  • Target version changed from 2.0 to 3.0

Also available in: Atom PDF