Results 1 to 10 of 10

Thread: Unit Tests?

  1. #1
    New user
    Join Date
    07-19-09.
    Posts
    19

    Default Unit Tests?

    Hi developers,
    I just wanted to ask and discuss eventually:
    Is there a "standard" way to write Unit tests to ensure the quality of your extensions.
    In additions is there a Testing Framework that Contao uses?
    http://www.phpunit.de/, http://seleniumhq.org/?
    On http://dev.contao.org/projects/typolight/repository i do not see a folder whwr there are test files otr something.
    In short how should i write automated tests or how do you do this?
    Leo, say something.
    thanks.

  2. #2
    New user
    Join Date
    07-19-09.
    Posts
    19

    Default Re: Unit Tests?

    Anyone?

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Unit Tests?

    Not me sorry. I'm still on Learner plates.

    You may be better asking this at the German forum if you can, as a lot more developers hang out there.
    http://www.contao-community.de

  4. #4
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Unit Tests?

    I'm not sure what you mean. How can you test the quality of an extension? Since all Contao interfaces are table editing interfaces, they all look the same, so what would you be testing.

    The Contao Framework provides many features, however they can be quite tricky to setup in certain cases, e.g. like permissions. About 15 things need to be in place to correctly check that a module provides user permissions and that they are correctly addressed.

    The best bet would be to start with user permissions for now. Admins will have all access, so they can perform all functions. A user (e.g. the client) should be able to logon, then create a News Archive (if allowed), delete a News Archive and then also EDIT the archive, add items, delete items, move items around and between archives, etc. Not sure if a user-test is what you're looking at.

  5. #5
    New user
    Join Date
    07-19-09.
    Posts
    19

    Default Re: Unit Tests?

    I mean for example that:
    http://www.symfony-project.org/book/...tional-Testing.

    When 15 things need to be in place one sets up the environment with the 15 things in place and runs the test
    like this for example:
    https://github.com/kberov/CGI--Simpl.../upload_info.t

  6. #6
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Unit Tests?

    That's what I meant. You can only test the interaction for Contao, eg.

    Create a new Archive
    Add an entry into an Archive
    Modify the Entry
    Move the Entry
    Delete the Entry
    Delete the Archive.

    That would test that an application like the News System is performing as it should. There isn't much else you can test.

    Each extension would take almost as much time to test as to write...

  7. #7
    New user
    Join Date
    07-19-09.
    Posts
    19

    Default Re: Unit Tests?

    Each extension would take almost as much time to test as to write...
    Yep I know. Actually tests must be written before the actual code.
    For a change(adding "\.") in a regex I needed to write 100 rows testing code.
    ...

    And then comes the maintenance time ... when one will be afraid to change something because it can be accidentally broken.
    Having automated tests, one can run them each time when he/she change something and this way code more confidently which actually saves time for debugging and hair pulling and unhappy users etc.
    That is how a software can safely evolve and not become unmaintainable monster.
    Otherwise why there are so many testing frameworks etc.

  8. #8
    User
    Join Date
    11-23-09.
    Location
    Valais, Switzerland
    Posts
    77

    Default Re: Unit Tests?

    Hello kberov,

    First of all, congratulation for the [i18nl10n] module!

    About UnitTest I wrote the same topic as you in the french forum 2 month ago :
    http://forum.contao.fr/extensions/co...res-t1529.html

    If you don't talk french the main point is that oelmekki made a great module :
    https://github.com/oelmekki/typolight_testing

    This is not so simple to use but really powerful, based on selenium and you can use MockObject.

    For small project I'm using NetBean's with phpunit. You can write UnitTest in method comment and NetBean's can generate it!
    Code:
        /**
         * Give the last day of the given month.
         * @return int (28,29,30,31).
         * @assert (2,2009) == 28
         * @assert (2,2008) == 29
         * @assert (4,2010) == 30
         * @assert (7,2008) == 31
         * @assert (8,2008) == 31
         * @assert (7,2010) == 31
         * @assert (8,2010) == 31
         * @assert (9,2008) == 30
         * @assert (12,2010) == 31
         * @assert (1,2011) == 31
         */
        public static function get_last_day_of_month($month, $year) {
            return date('t', mktime(0, 0, 0, $month, 1, $year));
        }
    Will generate :

    Code:
        /**
         * Generated from @assert (2,2009) == 28.
         */
        public function testGet_last_day_of_month() {
            $this->assertEquals(
                    28,
                    tool_date::get_last_day_of_month(2, 2009)
            );
        }
    
        /**
         * Generated from @assert (2,2008) == 29.
         */
        public function testGet_last_day_of_month2() {
            $this->assertEquals(
                    29,
                    tool_date::get_last_day_of_month(2, 2008)
            );
        }
    
        /**
         * Generated from @assert (4,2010) == 30.
         */
        public function testGet_last_day_of_month3() {
            $this->assertEquals(
                    30,
                    tool_date::get_last_day_of_month(4, 2010)
            );
        }
    
        /**
         * Generated from @assert (7,2008) == 31.
         */
        public function testGet_last_day_of_month4() {
            $this->assertEquals(
                    31,
                    tool_date::get_last_day_of_month(7, 2008)
            );
        }
    
        /**
         * Generated from @assert (8,2008) == 31.
         */
        public function testGet_last_day_of_month5() {
            $this->assertEquals(
                    31,
                    tool_date::get_last_day_of_month(8, 2008)
            );
        }
    
        /**
         * Generated from @assert (7,2010) == 31.
         */
        public function testGet_last_day_of_month6() {
            $this->assertEquals(
                    31,
                    tool_date::get_last_day_of_month(7, 2010)
            );
        }
    
        /**
         * Generated from @assert (8,2010) == 31.
         */
        public function testGet_last_day_of_month7() {
            $this->assertEquals(
                    31,
                    tool_date::get_last_day_of_month(8, 2010)
            );
        }
    
        /**
         * Generated from @assert (9,2008) == 30.
         */
        public function testGet_last_day_of_month8() {
            $this->assertEquals(
                    30,
                    tool_date::get_last_day_of_month(9, 2008)
            );
        }
    
        /**
         * Generated from @assert (12,2010) == 31.
         */
        public function testGet_last_day_of_month9() {
            $this->assertEquals(
                    31,
                    tool_date::get_last_day_of_month(12, 2010)
            );
        }
    
        /**
         * Generated from @assert (1,2011) == 31.
         */
        public function testGet_last_day_of_month10() {
            $this->assertEquals(
                    31,
                    tool_date::get_last_day_of_month(1, 2011)
            );
        }
    But what will be interessting is to generate the logic of test and not only the code writing. For example every money value must be tested the same way => no minus value, not more than the double can store...
    I will write a message blog about it some day...

    If you start to develop something, tell me I'm thinking about it since month.

  9. #9
    New user
    Join Date
    07-19-09.
    Posts
    19

    Default Re: Unit Tests?

    Salut,salut,salut, Sinergie. Je suis heureux q'il y a des gens qui pensent au logisiel comme il faut.
    I am really glad to read that Unit Tests are taken seriously.
    After writing the "Multilanguage Pages" I felt the need of making sure the extension will work with future versions of Contao, since I made some quite big sub-classing of the core to make it work as it is. The opposite is also true - I want to make sure that the extension will not break people's sites and thus thrown away as unusable.
    I will read your post. Now I am confident that there is really proved way to build scalable web applications using Contao.
    Thanks again.

  10. #10
    User
    Join Date
    04-10-11.
    Posts
    162

    Default Re: Unit Tests?

    Hi,

    I know this is an old post. Unit testing has become much more of a standard in PHP over the last year and I just wondered if there was any progress in terms of Unit Testing in Contao?

    I've had some success using PHPUnit to test classes that are used by my modules, but I have not been able to run tests on the modules themselves as the Module class requires a Database result to be passed to it which stops PHPUnit from loading the class.

    Anyone else have any experience or tips with Unit testing in Contao?

    Cheers

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •