Create first app Writing tests

Writing tests

Create automated tests to deliver good quality apps.

Introduction

You should always write tests for your app. Writing unit tests offers several key benefits that contribute to the overall quality, maintainability, and reliability of your app:

Overall, unit testing is an investment that pays off by improving the long-term stability and maintainability of your app.

How to write tests

To create a test, first create a Tests folder in your app's folder. Then, for each test create a separate PHP script. Following previous tutorials, we can add a simple test called RenderAllRoutes to our MyApp by creating a dedicated file:

./apps/external/MyCompany/MyApp/Tests/RenderAllRoutes.php
namespace HubletoApp\External\MyCompany\MyApp\Tests;
class RenderAllRoutes extends \HubletoMain\Core\AppTest {
  public function run(): void {
    $this->main->render('my-app');
    $this->main->render('my-app/contacts');
  }
}

Running a test

To run a test, use Hubleto CLI agent followingly:

php hubleto app test <appName> <testName>

You must provide full namespace of your app's loader class.

For example, to run a RenderAllRoutes created earlier, run following command:

php hubleto app test \HubletoApp\External\MyCompany\MyApp RenderAllRoutes
« Previous page
Custom UI components
Next page »
More reading
www.hubleto.com | Found a bug or missing something? Report an issue via GitHub.