本文介绍了单元测试/与Simulink / Stateflow的持续集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我如何在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)相关联? 是否有任何人使用这些或不同单元测试框架的经验? b $ bDoes anyone have experience in using those or different unit test frameworks?How to link this to continuous integration systems (i.e. Hudson)?推荐答案正如Craig所提到的,在R2013a中引入了一个MATLAB框架。此外,此框架添加了 TAPPlugin 在R2014a中输出测试任何内容。使用该协议,您可以使用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构建可能看起来像一个shell命令,启动MATLAB并运行所有测试: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创建要运行的套件,并将tap输出重定向到文件来运行它。您需要在这里修改细节,但也许这可以帮助您开始: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 runAllMyTestsimport 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:我将此主题用作第一 两个帖子面向新开发人员的博客今年推出 I used this topic as the first two posts of a new developer oriented blog launched this year 这篇关于单元测试/与Simulink / Stateflow的持续集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 02:56