Skip to content

Tests are part of the language

In many languages you first choose a test framework, install it and configure it. In Novis the test runner is part of nvs, and the assertions are in Core\Test:

<?nvs
// This program has a class and a test for it. `nvs test` runs the test.
use Core\Test;
class Cart
{
public static function total(int $price, int $count): int
{
return $price * $count;
}
}
final class CartTest
{
// `#[Test]` makes this method a test. You do not install a package for it.
#[Test]
public function multipliesPriceByCount(): void
{
Test::assertSame(Cart::total(250, 4), 1000);
}
}
// `nvs run` runs this line and not the test.
echo Cart::total(250, 2), "\n";
Output
500

nvs run runs the program. nvs test runs the methods with #[Test]:

CartTest
✓ multipliesPriceByCount 0.2 ms
0 failed, 1 passed, 0 skipped, 0 flaky in 1 ms

Each test runs on its own, so one test cannot change a value that another test reads.

Read more in Syntax: writing tests and Reference: nvs test.