Test with Frisk!

For a while now, I’ve had a renewed interesting testing applications – unit, functional, performance, etc – and have been learning all I can about the software you can use to run these tests. Obviously, one of the mainstays of the PHP world is PHPUnit for unit testing. There’s a few others out there that are good for other kinds of testing – too many to name (and lots that aren’t written in PHP).

Lately, though, I’ve been looking more at testing the frontend of applications and their flow. I started looking around at the current testing tools and found some I wanted to use, but I wanted more to know how they worked. So, as an exercise, I started on Frisk, a light-weight simple testing framework that has some of the basics of functionally testing, nothing fancy though. Oh, and of course it’s open sourced so you can take a look at the work behind it too.

It’s not a complete testing tool, but it does work. I’ve thrown together a simple example of how I’ve used it to test two things on the Joind.in site – the homepage content and the result of a login:

JoindinTest.phps

When this file is dropped in the “tests” directory and the “frisk” executable is run, it’ll execute these tests and check the results of those requests. The “ji-enygma.localhost” is a reference to my local Joind.in instance. The results are spit back out as a PHP array that reports the results of each part of the test (pass/fail) split out by test function name and action/assert result:

Start!

=====================
ending status: Array
(
    [JoindinTest] => Array (
            [testHomepageContent] => Array (
                    [ActionGet] => Array (
                            [0] => pass
                            [1] => 
                        )
                    [AssertContains] => Array (
                            [0] => pass
                            [1] => 
                        )
                )
            [testValidLogin] => Array (
                    [ActionGet] => Array (
                            [0] => pass
                            [1] => 
                        )
                    [ActionSubmitform] => Array (
                            [0] => pass
                            [1] => 
                        )
                    [AssertContains] => Array (
                            [0] => fail
                            [1] => AssertContains: Term not found
                        )
                )
        )
)

The project is hosted on Github so you can grab the source, fork it and play with the assertions and actions (or helpers!) and check out the project wiki for complete details on what the project has to offer.

Category: PHP, Testing 2 comments »

2 Responses to “Test with Frisk!”

  1. Mike Willbanks

    Chris,

    I am curious as to how this is truly functional since it would be hard to actually test within different browsers. Although I do like how this works, to me it seems like a perfect extension to the current PHPUnit for more backend types of functional programming. You may have to utilize the more annoying @covers docblock attribute but it seems like it is still more or less unit testing + a slight amount of functional testing.

  2. Mark Willis

    This tests the functional aspect of the front-end rather then the design aspects some examples would be:

    Checking a form with produce correct error message for invalid data. This would normally be a manual process but can be automated with this type of test script.

    Also – route checking after changes, if a page is changed – you can see if you can still access it through a predefined route.

    I have used http://www.simpletest.org/ a fair bit with some other projects ( I made some modifications to allow better CLI use )


Leave a Reply



Back to top