Skip to content

UnitTest

StefansArya edited this page Aug 11, 2019 · 1 revision

Using Unit Test is pretty simple, all you need is just add a PHP file inside /tests folder.

unit_test

Note

In this folder you can add as many file as you want for testing.
But you shouldn't declare any function/class/variable outside of function scope if you don't want any conflict with other test file.

Running tests

Every test file will be tested after calling this command line.

$ scarlets test

Create new test file

The test file must be a PHP file and it can contain more than one test case.
Before you're doing any test it's better to describe it first what it going to be tested.

$describe("Your tests file description or title");

And after that you can create new scope of function as a sandbox of your code.

$it("Testing something", function($assert){
  $result = 3 * 2;

  // Make sure it return 6
  $assert::equal($result, 6);
});

If there are no error and incorrect result, it would return Success on the CLI.
But on different case, below will return Failed and the execution will be returned.

$it("Testing something", function($assert){
  $result = 3 + 2;

  // Make sure it return 6
  $assert::equal($result, 6);

  // The execution won't reach here
  // ...
});

Notes

This documentation still haven't finished yet because some feature still being developed.

Clone this wiki locally