Skip to content

Code testing

Nathan Gray edited this page May 21, 2026 · 4 revisions

Introduction

Egroupware uses PHPUnit in order to test server side codes and Web Test Runner for webComponent testing. There is usually a test folder in each module or section which holds test codes. Test codes are written in the matching language as the code under test (PHP or TypeScript). See the test framework docs for more information about testing with that framework.

To run the full PHPUnit test suite:

php vendor/bin/phpunit --configuration doc/phpunit.xml

To run the full WTR test suite:

npm run jstest

How to run a test

Install Dependencies

In order to run PHPUnit tests, first of all you need to install PHPUnit on your dev machine. You can find the installation instruction Here

For WTR, you need the Web Test Runner framework and Playwright

npx playwright install --with-deps chromium firefox

Run a test in CLI

To run the full PHPUnit test suite, run php vendor/bin/phpunit --configuration doc/phpunit.xml

You can run tests with phpunit command in cli, which usually is running a test against a file to be tested:
phpunit --bootstrap [FileNeedsToBeTested] [RelativeTestFile]
For instance:

> phpunit --bootstrap api/src/loader/security.php api/src/loader/test/SecurityTest.php
PHPUnit 5.1.3 by Sebastian Bergmann and contributors.

...............................                                   31 / 31 (100%)

Time: 1.06 seconds, Memory: 8.00Mb

OK (31 tests, 812 assertions)

The above example shows that our security.php has been gone through 31 tests and 100% passed all of them.

You can run all tests for Egroupware using the phpunit command:
phpunit -c doc

PHPUnit 5.7.4 by Sebastian Bergmann and contributors.

SSSS............................................................. 65 / 76 ( 85%)
...........                                                       76 / 76 (100%)

Time: 25.61 seconds, Memory: 30.00MB

OK, but incomplete, skipped, or risky tests!
Tests: 76, Assertions: 1240, Skipped: 4.

4 tests were skipped in this case because of missing extensions.

Run tests in Netbeans (V8+)

It would be more convenient to be able to run all tests just by pressing one click. For that purpose we can configure PHPUnit test on egroupware's project inside Netbeans and tell the Netbeans to run all or a single test for us, pretty good right?.

PHPUnit in Netbeans needs another module called Skeleton Generator Script which you need to install before the configuration. Learn more about Skeleton Generator installation.

  • Step 1: Go to Tools -> Options -> PHP -> Frameworks & Tools and configure PHPUnit Script and Skeleton Generator Script.


    Netbeans options


  • Step 2: Go to project properties -> Testing. There you can add all test folders into "Test Directories", then check mark the PHPUnit as Testing Provider, and click OK.


    Netbeans properties

    Note: In case you're wondering where did your test folders just vanish!? Do Not Panic! Netbeans removes them just from Source Files in Projects tree and will add them as Test Files Sections under the project root, and the original test folders are untouched.

  • Step3: Now we have everything ready to run the tests. We just need to press "Alt + F6" or right click on project and run Test.


    Running tests

    For running individual test we can go to each particular test file and run that test.

Clone this wiki locally