我使用Drone作为持续集成(CI)服务器。
使用此脚本启动测试:
图像:无人机/ matlab:R2014a脚本: - cd测试 - matlab -nodesktop -nosplash -r ci_run_tests
…
大多数持续集成系统不会解析结果或了解正在使用的测试,但会检查所调用程序的退出状态。
为了发出错误信号,程序需要退出其他东西但是 0 。
0
虽然提到的测试脚本有一个 exit(1) 好像是 testrunner 在测试失败时不会引发异常。因此,要检查失败的测试,您需要计算它们的数量:
exit(1)
testrunner
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))); results = runner.run(suite); % Count number of failed tests. Exit(1) if greater than 0 if nnz([results.Failed]) exit(1); end catch e; disp(e.getReport); exit(1); end; exit force;
当你想到它时,那就是你真正想要的行为:异常总是停止执行任何抛出它的东西。因此,您的测试套件会在第一次遇到错误时停止,而不会显示任何其他错误。
无人机是否支持JUnit样式的XML工件?如果确实如此,则另一种解决方案是使用 XMLPlugin 用于MATLAB单元TestRunner而不是TAPPlugin。