Skip to content


Unit testing framework

SPM testing is performed using the MATLAB Unit Testing Framework.

SPM unit tests are stored in the spm/tests directory. The can be executed by calling the spm_tests function. Individual tests can be run as follow:

>> spm_tests test spm_Ncdf                     

SPM12: spm_tests                                   12:00:00 - 01/01/2023
Running test_spm_Ncdf
Done test_spm_Ncdf

   7 Passed, 0 Failed, 0 Incomplete.
   0.016786 seconds testing time.

Some tests require input data that can be downloaded from here. This archive has to be unpacked into a spm/tests/data directory before running the tests.

Continuous integration

Continuous integration on GitHub takes place with MATLAB GitHub Actions. The configuration file for the testing workflow is available here and the outcomes are available from the GitHub Actions tab.

Adding unit tests

To add new unit tests to SPM, please follow the instructions from the MATLAB documentation. Function-based unit tests are favoured for now.

To write unit tests for SPM function spm_example.m, create a file spm/tests/test_spm_example.m containing:

function tests = test_spm_example
% Unit Tests for spm_example

% Copyright (C) 2023 Wellcome Centre for Human Neuroimaging

tests = functiontests(localfunctions);

function test_spm_example_1(testCase)
exp = pi;
act = 3.1415926535897;
tol = 1e-12;
testCase.verifyEqual(act, exp,'AbsTol',tol);

function test_spm_example_2(testCase)

Regression tests

Beyond unit tests, regression tests are also performed on the SPM codebase (to be documented).