A light, unit testing framework for Typescript, created mostly to assist with the understanding of how unit testing frameworks function. This framework includes both a test runner and assertion library. It is very simple to setup and has no additional dependencies.
Future iterations will include mocking and dependency injection features.
teradaktyl can be installed via npm
npm install --save-dev teradaktyl
teradaktyl can be executed from the command-line and takes 1 parameter; the name of the folder where the your Typescript tests are compiled to.
teradaktyl build/tests
Add a "test" script into the scripts sections of your projects package.json file.
"scripts": {
"test": "teradaktyl build/tests"
}
Tests can now be executed from a terminal using the following
npm test
Test Driven Development is a software development methodology for facilitating clean, minimal code. It is based around the process of first writing a test to satisfy a requirement, and then writing the code to get the test to pass.
Assume we have a requirement to create a function which will add 2 numbers together
In the root folder of your project, create a new folder named tests
Within this tests folder, create a new Typescript file named sum.test.ts and insert the following code.
import { Teradaktyl } from 'teradaktyl';
import { Add } from 'sum';
Teradaktyl.Test("Assert 1 add 2 equals 3", (assert: Teradaktyl.IAssertable) => {
const result = Add(1, 3);
assert.AreEqual(3, result);
});
This test will fail with the error of cannot find module sum.
In the root folder of your project, create a new folder named src
Within this src folder, create a new Typescript file named sum.ts and insert the following code.
export function Add(value1: number, value2: number) {
return value1 + value2;
}
The test should now run successfully.
The ability to inject dependencies into classes to facilitate single unit testing.
The ability to mock dependencies injected into classes.