编辑:现在这变得更加容易,并且随着MATLAB 的 Jenkins 插件 https://plugins.jenkins.io/matlab/
原答案:
正如 Craig 提到的,R2013a 中确实引入了 MATLAB 框架。此外,该框架还添加了一个TAPP插件 http://www.mathworks.com/help/matlab/ref/matlab.unittest.plugins.tapplugin-class.html在 R2014a 中输出测试任何协议 http://testanything.org/。使用该协议,您可以使用 TAPPlugin 设置 CI 构建(例如Jenkins https://wiki.jenkins-ci.org/display/JENKINS/TAP+Plugin, TeamCity https://github.com/pavelsher/teamcity-tap-parser),这样如果测试失败,CI 系统可能会导致构建失败。
您的 CI 构建可能看起来像启动 MATLAB 并运行所有测试的 shell 命令:
/your/path/to/matlab/bin/matlab -nosplash -nodisplay -nodesktop -r "runAllMyTests"
然后 runAllMyTests 创建要运行的套件并运行它,并将 Tap 输出重定向到文件。您需要在这里调整细节,但这也许可以帮助您开始:
function runAllMyTests
import matlab.unittest.TestSuite;
import matlab.unittest.TestRunner;
import matlab.unittest.plugins.TAPPlugin;
import matlab.unittest.plugins.ToFile;
try
% Create the suite and runner
suite = TestSuite.fromPackage('packageThatContainsTests', 'IncludingSubpackages', true);
runner = TestRunner.withTextOutput;
% Add the TAPPlugin directed to a file in the Jenkins workspace
tapFile = fullfile(getenv('WORKSPACE'), 'testResults.tap');
runner.addPlugin(TAPPlugin.producingOriginalFormat(ToFile(tapFile)));
runner.run(suite);
catch e;
disp(e.getReport);
exit(1);
end;
exit force;
EDIT:我用这个主题作为first http://blogs.mathworks.com/developer/2015/01/20/the-other-kind-of-continuous-integration/ two http://blogs.mathworks.com/developer/2015/01/29/tap-plugin/的帖子新的面向开发人员的博客 http://blogs.mathworks.com/developer/今年推出