_UnitTest/ subdirectory inside the module folder and are run with pytest. The cModuleTemplate and cppModuleTemplate test files are the canonical reference implementations.
Test file structure
test_. The test function inside must also start with test_.
Writing a unit test
The pattern used throughout Basilisk separates the pytest entry point from the actual simulation function. This lets the test run both underpytest and as a standalone Python script.
Parameterized tests
For modules where you want to test multiple input scenarios, usepytest.mark.parametrize. The cppModuleTemplate test demonstrates this pattern:
Setting up the simulation
Create the simulation container
Every test starts with an empty
SimBaseClass and at least one process and task:Instantiate and configure the module
Create the module, set its
ModelTag, add it to the task, and set its parameters:Create and connect input messages
Build a standalone message with the desired payload and subscribe the module’s input functor to it:
Set up recorders
Attach a recorder to any output message you want to inspect, and optionally a variable logger for internal module state:
Message recording and verification
After running the simulation, access the recorded data as NumPy arrays:unitTestSupport module provides comparison helpers:
Running tests with pytest
From the Basilisk project root:if __name__ == "__main__": block at the bottom of every test file.
Module checkout list
Before submitting a module for review, verify each item in this checklist. Branch and build- Branch is rebased on the latest
developbranch. - Clean build passes (
python3 conanfile.pythen build). -
python run_all_test.pyshows all tests passing.
- Variables follow the Basilisk coding style guidelines.
- Four spaces are used for indentation, not tabs.
- All numeric literals with physical meaning have inline unit comments (
//!< [m],//!< [s], etc.).
- All input and output messages are declared in the
.iSWIG interface file. - Code contains appropriate general comments.
- Code contains Doxygen-compatible function descriptions and variable definitions.
-
SelfInitdeclares all output messages (C modules only). -
Resetresets all time-varying state variables and checks that required messages are connected. - Module uses
bskLogger(orBSK_PRINTfor general support libraries that are not modules). - C++ modules expose user-configurable variables through setter/getter methods with input validation.
- Module folder contains a
myModule.rstdocumentation file. - The RST file includes: Executive Summary, Message Connection Descriptions, Module Assumptions and Limitations, and User Guide sections.
- Documentation builds successfully with Sphinx.
-
_UnitTest/folder exists and contains a file namedtest_myModule.py. - Test function name starts with
test_. - Test docstring describes what is being validated (Validation Test Description, Description of Variables Being Tested).
- Test exercises the module in isolation and creates all required input messages.
- Test checks output for all relevant input and configuration conditions.
- Test compares against analytically computed or independently verified truth values.
- Test can be run both with
pytestand directly withpython test_myModule.py.
- A release note snippet
.rstfile has been added todocs/source/Support/bskReleaseNotesSnippets/. -
docs/source/Support/bskReleaseNotes.rsthas not been edited directly.