单元测试/与 Simulink/Stateflow 的持续集成 [英] Unit testing/continuous integration with Simulink/Stateflow
问题描述
如何在 Simulink 或者最好是 Stateflow 中执行单元测试?
How can I perform unit testing in Simulink, or preferably, Stateflow?
我喜欢敏捷软件方法,包括测试驱动开发.我负责安全关键控制软件的开发,我们使用 Matlab/Simulink/Stateflow 进行开发.之所以选择此工具集,是因为它与工厂(硬件)模型有关联.(模型在环,硬件在环)
I'm a fan of agile software methods, including test driven development. I'm responsible for the development of safety critical control software and we're using Matlab/Simulink/Stateflow for the development of it. This toolset is selected because of the link with plant (hardware) models. (model-in-the-loop, hardware-in-the-loop)
我在 Stackoverflow 上找到了一些链接:MATLAB 的单元测试框架:xunit, slunit 和 doctest.
I have found some links on Stackoverflow: Unit-testing framework for MATLAB: xunit, slunit and doctest.
- 有没有人使用过这些或不同的单元测试框架?
- 如何将其链接到持续集成系统(即 Hudson)?
推荐答案
原始答案:
正如 Craig 所提到的,R2013a 中确实有一个在 MATLAB 中引入的框架.此外,该框架添加了 TAPPlugin 在 R2014a 中输出 Test Anything Protocal.使用该协议,您可以使用 TAPPlugin 设置您的 CI 构建(例如.Jenkins, TeamCity) 这样 CI 系统可以在测试失败时构建失败失败.
As Craig mentioned there is indeed a framework in MATLAB introduced in R2013a. Furthermore, this framework added a TAPPlugin in R2014a which outputs the Test Anything Protocal. Using that protocol you can set up your CI build with a TAPPlugin (eg. Jenkins, TeamCity) so that the CI system can fail the build if the tests fail.
您的 CI 构建可能看起来像一个用于启动 MATLAB 并运行所有测试的 shell 命令:
Your CI build may look like a shell command to start MATLAB and run all your tests:
/your/path/to/matlab/bin/matlab -nosplash -nodisplay -nodesktop -r "runAllMyTests"
然后 runAllMyTests 创建要运行的套件并运行它,并将点击输出重定向到文件.您需要在此处调整细节,但也许这可以帮助您入门:
Then the runAllMyTests creates the suite to run and runs it with the tap output being redirected to a file. You'll need to tweak specifics here, but perhaps this can help you get started:
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;
我将此主题用作 first 今年发布的新的面向开发人员的博客的两篇帖子
I used this topic as the first two posts of a new developer oriented blog launched this year
这篇关于单元测试/与 Simulink/Stateflow 的持续集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!