-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom testTask instead of built-in TestTask to enable passing ex…
…ample script filenames as parameter to test class definition.
- Loading branch information
Showing
4 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function results = testTask(tags) | ||
% Run unit tests | ||
|
||
arguments | ||
tags string {mustBeText} = ""; | ||
end | ||
|
||
import matlab.unittest.TestRunner; | ||
import matlab.unittest.TestSuite; | ||
import matlab.unittest.Verbosity; | ||
import matlab.unittest.plugins.XMLPlugin; | ||
import matlab.unittest.parameters.Parameter; | ||
|
||
projObj = currentProject; | ||
|
||
% Get list of example scripts in path | ||
exName = {dir(fullfile(projObj.RootFolder,'toolbox/examples','**/*.m')).name}'; | ||
exName = exName(isFileOnPath(exName)); | ||
exParam = Parameter.fromData('exName',exName); | ||
|
||
suite = TestSuite.fromProject(projObj,'ExternalParameters',exParam); | ||
if strlength(tags)>0 | ||
suite = suite.selectIf("Tag",tags); | ||
else | ||
disp('No tag was passed as input. All test cases will be executed.'); | ||
end | ||
|
||
if isempty(suite) | ||
warning('No tests were found with tag(s) "%s" and none will be executed.',strjoin(tags,', ')); | ||
end | ||
|
||
runner = TestRunner.withTextOutput('OutputDetail', Verbosity.Detailed); | ||
runner.addPlugin(XMLPlugin.producingJUnitFormat(fullfile(projObj.RootFolder,'results.xml'))); | ||
|
||
results = runner.run(suite); | ||
results.assertSuccess; | ||
|
||
end | ||
|
||
function onPath = isFileOnPath(filename) | ||
onPath = boolean(zeros(1,length(filename))); | ||
for ii = 1:length(filename) | ||
onPath(ii) = exist(filename{ii},"file")>0; | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
resources/project/_BcHeyeYYWxz6MENB98iTz25sSI/-Q4cJnxWta-5Ny2GvhmbmxvrPv0d.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Info> | ||
<Category UUID="FileClassCategory"> | ||
<Label UUID="design"/> | ||
</Category> | ||
</Info> |
2 changes: 2 additions & 0 deletions
2
resources/project/_BcHeyeYYWxz6MENB98iTz25sSI/-Q4cJnxWta-5Ny2GvhmbmxvrPv0p.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Info location="testTask.m" type="File"/> |