Discovering the Bnlang Test Runner
The Bnlang Test Runner is the official tool for writing and running tests in the Bnlang ecosystem.
It provides a simple API for defining tests, assertions, and hooks, ensuring reliable and maintainable code.
With the test runner, you can automate quality checks and confidently refactor projects.
Writing a Simple Test
const { test } = require("bnl_test");
test("addition works", (t) => {
t.equal(2 + 2, 4);
});
Assertions
Assertions are checks that confirm expected outcomes.
Common methods include t.equal
, t.notEqual
, t.ok
, and t.fail
.
Hooks
The runner supports lifecycle hooks:
before
→ Runs once before all tests.after
→ Runs once after all tests.beforeEach
→ Runs before each test.afterEach
→ Runs after each test.
Example with Hooks
const { test } = require("bnl_test");
test.before(() => console.log("Setup"));
test.after(() => console.log("Teardown"));
test("check value", (t) => {
const x = 10;
t.ok(x > 5);
});
Best Practices
- Group related tests for readability.
- Keep test functions small and focused.
- Use hooks for setup/teardown logic.
- Automate tests in CI/CD pipelines for reliability.