Unit testing/continuous integration with Simulink/Stateflow

后端 未结 8 1353
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 05:22

How can I perform unit testing in Simulink, or preferably, Stateflow?

I\'m a fan of agile software methods, including test driven development. I\'m responsible for the d

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 05:37

    Matlab (since 2013b) has built-in support for xUnit, in the form of the Unit Testing Framework. I haven't used it but since it's possible to run simulink from Matlab with sim() then this framework can be used to test your simulink models. You libraries and possibly models will need a wrapper to execute it as the other answerers have noted.

    There are plenty of examples on the Mathworks site, unfortunately non of them run simulink models. I'd code an example for you, but I don't have ML2013b :-(

    In order to initiate your tests from a CI (I use Jenkins) then you can call matlab to run a .m file that runs your test suite, this example cmd script will call Run_Tests.m from Matlab:

    IF EXIST "C:\Program Files (x86)\MATLAB\R2013b\bin\win32\matlab.exe" (
        REM WinXP
        "C:\Program Files (x86)\MATLAB\R2013b\bin\win32\matlab.exe" -r "Run_Tests;exit" -logfile matlab.log
    ) ELSE (
        REM Win7
        "C:\Program Files\MATLAB\R2013b\bin\win32\matlab.exe" -r "Run_Tests;exit" -logfile matlab.log
    )
    

    Note that if a startup.m exists in the directory that you call Matlab from, then it'll be executed automatically beforeRun_Tests.m`.

提交回复
热议问题