Skip to main content

nada-test: Nada Testing Framework

nada-test is a powerful and flexible testing framework for Nada programs. It enables developers to write dynamic tests that are generated at runtime, offering more flexibility than traditional YAML test files.

Features

  • Dynamic test generation at runtime
  • Easy-to-write test functions using Python
  • Seamless integration with nada projects
  • Support for both standalone usage and integration with pytest
  • Flexible input and output specification for test cases

Installation

You can install nada-test in a Nada project using pip:

pip install nada-test

Setup

To use nada-test as your test framework, you’ll need to configure it in your nada-project.toml file. This allows the nada test command to automatically run your tests using the nada-test framework. Here’s how you can set it up:

Add the following to your nada-project.toml file to set nada-test as your default test runner and point it to the ./tests directory:

[test_framework.nada-test]
command = "nada-test ./tests"

This setup ensures that all tests inside the ./tests directory will be executed when you run nada test.

Writing tests

You can use nada-test to write both functional and class-based tests for your programs. Tests are decorated with @nada_test(program="program_name") to specify which program is being tested. Below are two examples showing how to test a basic addition program.

Tests should be written in a Python file located in the directory you specified during the setup (e.g., ./tests or any custom test directory). Below are examples of how to test a basic addition program using both styles.

Functional style test

tests/addition_test.py
loading...

Class-based test

tests/addition_test.py
loading...

Running tests

After writing your tests in the specified directories, you can run them using the following command:

nada test

This will execute all the tests configured in your nada-project.toml file. The output will show you the results of your test suite.