We use a series of unit and integration tests to make sure the code behaves as expected and to also help in development.
If you are not sure what unit and integration tests are, check the excellent chapter about that in the Turing way.
You need to install MOxUnit for matlab and octave to run the tests.
Note the install procedure will require you to have git installed on your computer. If you don't, you can always download the MoxUnit code with this link.
Run the following from a terminal in the folder where you want to install
MOxUnit. The make install
command will find Matlab / Octave on your system and
make sure it plays nice with MoxUnit.
NOTE: only type in the terminal what is after the $
sign:
# get the code for MOxUnit with git
git clone https://github.com/MOxUnit/MOxUnit.git
# enter the newly created folder and set up MoxUnit
cd MOxUnit
make install
If you want to check the code coverage on your computer, you can also install MOcov for matlab and octave. Note that this is also part of the continuous integration of the bids-matlab, so you don't need to do this.
To run the tests we used the examples data sets from the bids-examples repository.
The tests won't run unless you have a copy of that repository in the tests
folder:
cd tests
git clone git://github.com/bids-standard/bids-examples.git --depth 1
To get more complex data sets, to test things you can use datalad.
mkdir data
datalad clone https://github.com/OpenNeuroDatasets/ds000001.git
datalad get ds000001/sub-01/
datalad clone https://github.com/OpenNeuroDatasets/ds000117.git
datalad get ds000117/sub-01/ses-mri/func
datalad get ds000117/sub-01/ses-mri/fmap
There are a some help functions you need to add to the Matlab / Octave path to run the tests:
addpath(fullfile('tests', 'utils'))
From the root folder of the bids-matlab folder, you can run the test with one the following commands.
moxunit_runtests tests
# Or if you want more feedback
moxunit_runtests tests -verbose
You can use the following function template to write more tests.
function test_suite = test_functionToTest()
% This top function is necessary for mox unit to run tests.
% DO NOT CHANGE IT except to adapt the name of the function.
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions = localfunctions(); %#ok<*NASGU>
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end
function test_function_to_test_basic()
%% set up
%% data to test against
%% test
% assertTrue( );
% assertFalse( );
% assertEqual( );
end
function test_function_to_test_other_usecase()
%% set up
%% data to test against
%% test
% assertTrue( );
% assertFalse( );
% assertEqual( );
end
If you need to load a dummy datasets check the layout_timing
function as it as
a list of all the bids-matlab datasets and how loing it takes (more or less) to
run layout on each.