Procedure to create test cases externally for testing the model

6 views (last 30 days)
We wanted to create the test cases externally and to import them to Simulink tool and test the model using these test cases.
So, I wanted a detailed procedure on how to create test cases (what all should be included) and testing the model using these cases.
Could you please provide the sample also.
How to perform SIL and MIL?

Answers (1)

Shishir Reddy
Shishir Reddy on 17 Jul 2025
Hi Paturi
Kindly refer to the following steps to get an overview on creating test cases externally, importing them into Simulink and performing SIL and MIL simulations.
1. Creating Test Cases Externally
These test cases can be created in MATLAB as arrays or tables, or save them in files like Excel or CSV.
testInputs = [0 1; 1 0; 1 1; 0 0]; % Rows represent different test cases
expectedOutputs = [1; 0; 1; 0]; % Expected outputs corresponding to each test case
2. Importing Test Cases into Simulink
To use these test cases in Simulink, use blocks like 'From Workspace' or 'From File' to bring input data into your model an run simulations for each test case using a MATLAB script loop as follows -
for i = 1:size(testInputs,1)
u1 = testInputs(i,1);
u2 = testInputs(i,2);
simOut = sim('your_model', 'SimulationMode', 'normal', 'SaveOutput', 'on', 'OutputSaveName', 'yout');
actualOutput = simOut.get('yout');
fprintf('Test case %d: Expected = %d, Actual = %d\n', i, expectedOutputs(i), actualOutput);
end
3. MIL (Model-in-the-Loop) simulation:
Run your Simulink model simulations using your test cases to verify that the model behaves as expected. The steps above describe MIL testing.
4. SIL (Software-in-the-Loop) simulation:
Generate code from your Simulink model (using Simulink Coder), then run that code inside Simulink or on your computer to check if the generated code matches the model behavior.
For more information regarding 'MIL' and 'SIL' simulations, kindly refer the following documentations -
I hope this helps

Categories

Find more on Test Model Components in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!