Skip to content

Commit

Permalink
Fix: Improve test coverage (#28)
Browse files Browse the repository at this point in the history
* Only track coverage for type classes from latest version

* Test instance display

* Update testInstanceSaveLoad.m

Call string() in order to test the getDisplayMethod for the schema class

* Rename test to InstanceTest

* Update update.yml

---------

Co-authored-by: Update openMINDS_MATLAB by ehennestad <>
  • Loading branch information
ehennestad authored Oct 30, 2024
1 parent fbc8b6d commit b7adf56
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/badges/tests.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Update openMINDS_MATLAB
name: Run tests

on:
# Triggers the workflow on push to any branch other than main or PR to main
# This way tests will run on any push to a feature branch and when feature
# branches are merged to main, but not repeated when PRs are actually merged.
push:
branches-ignore: ["main", "pipeline", "gh-badges"]
branches-ignore: ["pipeline", "gh-badges"]
paths-ignore:
- '*README.md'
- '*md'
Expand Down
13 changes: 13 additions & 0 deletions tools/tasks/testToolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@ function testToolbox(varargin)
% Use the openMINDS_MATLAB setup to download controlled instances
run( fullfile(projectRootDirectory, 'code', 'setup.m') )

codeFolder = fullfile(projectRootDirectory, "code");
codecoverageFileList = getCodeCoverageFileList(codeFolder); % local function

matbox.tasks.testToolbox(...
projectRootDirectory, ...
"CreateBadge", true, ...
"CoverageFileList", codecoverageFileList, ...
varargin{:} ...
)
end

function fileList = getCodeCoverageFileList(codeFolder)
L = cat(1, ...
dir( fullfile(codeFolder, '+openminds', '**', '*.m') ), ...
dir( fullfile(codeFolder, 'internal', '**', '*.m') ), ...
dir( fullfile(codeFolder, 'schemas', 'latest', '**', '*.m') ));

fileList = fullfile(string({L.folder}'),string({L.name}'));
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
classdef testInstanceSaveLoad < matlab.unittest.TestCase
% testInstanceSaveLoad Unit test for save and load operations on OpenMINDS types
classdef InstanceTest < matlab.unittest.TestCase
% InstanceTest - Unit test for creation and save/load of OpenMINDS instances

% Automatically generate a test case for each schema type
properties (TestParameter)
Expand Down Expand Up @@ -30,6 +30,15 @@ function testCreateSchema(testCase, SchemaType)
% Attempt to create an object of the schema class
instance = schemaFcn();
testCase.assertInstanceOf(instance, 'openminds.abstract.Schema')

testCase.verifyWarningFree( @(i)dispNoOutput(instance) )

strRep = string(instance);
testCase.verifyClass(strRep, 'string')

function dispNoOutput(instance) %#ok<INUSD>
c = evalc('disp(instance)'); %#ok<NASGU>
end
end

function testSaveLoadForSchema(testCase, SchemaType)
Expand Down

0 comments on commit b7adf56

Please sign in to comment.