pxt-ev3/libs/tests
2018-01-04 09:23:28 -08:00
..
_locales use common packages tests implementation (#171) 2018-01-04 09:23:28 -08:00
platformoverrides.ts use common packages tests implementation (#171) 2018-01-04 09:23:28 -08:00
pxt.json use common packages tests implementation (#171) 2018-01-04 09:23:28 -08:00
README.md added test framework (#113) 2017-12-19 07:07:50 -08:00

tests

A unit test framework

Defining tests

Tests are registered as event handlers. They will automatically run once on start is finished.

tests.test("lgB set speed 10", () => {
    motors.largeB.setSpeed(10);
    loops.pause(100)
    tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
});

Assertions

The library has various asserts that will register fault. Note that since exceptions are not available, assertion failure do not stop the program execution.

  • assert checks a boolean condition
tests.assert("speed positive", motors.largeB.speed() > 0)
  • assert close checks that a numberical value is within a particular range
tests.assertClose("speed", motors.largeB.speed(), 10, 2)
tests