writing and performing tests

In my last post, I described how to get a testing environment for your eZ Publish developments. This was in my previous post.

Now it's time to go further on write your first test and run it.

This is not a PHPUnit tutorial the goal is to give you a first step and some clues to avoid brainstorming gapes.

Ok so lets try and write our first test.

1 / First steps

1.1 / the folder structure

The statement is, you're coding your new extension called mynewextension. As your are making some special things out of eZ Publish, you've written your own class MyClass. So the folder structure of your extension should look like this :

mynewextension
|__ classes |__ myclass.php

...

So first you'll have to create a tests folder where all your tests will be. Then replicate your code folder structure in your test folder. so things should look like :

Ok so, the script above show a suite.php. I've made the choice to show you a suite script extending ezpDatabaseTestSuite because it will be the most interesting. I'll give you more details about databases below. At this point the important line is :

this->addTestSuite('MyClassTest');

This is how to register your test case in the test suite.

1.2.2 / The test

On the same base as the suite, the test case will extend the ezpTestCase class or the ezpDatabaseTestCase. As you can gesse, we will use the second one in our example.