Simulink Exercise Assessment Tests in MATLAB Course Designer
Assessment tests let you automatically test learner solutions to Simulink® exercises in MATLAB® Course Designer™.

For an example of how to create a Simulink exercise, see Create Simulink Exercise Using MATLAB Course Designer.
Open Task Solution
Open your course in MATLAB Course Designer. Navigate to the exercise in which you want to add assessment tests and click Edit.
To open the solution for the task in which you want to add assessment tests:
In the task pane, click the task.
Add a solution if you have not already done so. To add a solution, see Add Task Solution.
If the solution is open, click the Solution tab. Otherwise, on the Edit Task tab, in the left navigation pane, click Solution. Then, next to the solution filename, click Open.
The solution includes an Assessment pane that helps you add tests.

Add Tests with Dependencies on Block Diagrams
To test elements such as blocks and connections, you must select the elements and then add the tests. The elements can be in the solution model or its subsystems.

As you navigate the model hierarchy, only the tests for the current block diagram are enabled for editing. The tests for other block diagrams are dimmed.
To edit a test for another block diagram, click the test to open the corresponding block diagram.
To highlight the blocks or signal lines that correspond with a test, click the test.

Add Test for Block Existence
To test that the learner solution contains the specified blocks:
In the current block diagram, select one or more blocks.
In the Assessment pane, select Add Test > Block existence. A new test appears for each selected block.

Learners receive a question about whether the model contains a specific type of block, such as a Step block.

When you test the existence of more than one block of the same type, a parenthetical provides the number of expected blocks of that type.

Add Test for Block Parameter Value
To test that block parameter values match what you specify:
In the current block diagram, select one or more blocks.
In the Assessment pane, select Add Test > Block parameter value. A new test appears for each selected block.
In the Parameter list, select the block parameter to test. Select only documented block parameters. Undocumented block parameters are for internal use only.
Check that the parameter value matches expectations.
To test additional parameter values for the same block, click Add Parameter. For each addition, select the block parameter to test and check the parameter value.
If you update the value of a block parameter, the test automatically updates to reflect the new value.

Learners receive a question about whether the block has the correct parameter settings.

Add Test for Signal Line
To test that signal lines connect blocks as expected:
In the block diagram, select one or more signal lines.
In the Assessment pane, select Add Test > Signal line. A new test appears for each selected signal line.
If a signal branches to more than one destination, optionally, test that the signal connects to additional destinations. For each destination that you want to test, click Add Destination and select the block port that receives the signal.

Learners receive a question about whether a signal line connects the blocks.

Add Test for Model Parameter Value
To test that the value of a model parameter matches what you specify:
Select Add Test > Model parameter value.
In the Parameter list, select the model parameter to test.
Check that the nested parameter value matches expectations.
To test additional model parameter values, click Add Parameter. For each addition, select the model parameter to test and check the parameter value.
If you update the value of a model parameter, the test automatically updates to reflect the new value.

Learners receive questions about whether the selected model parameters have the correct settings.

Add Test for Signal Data
To test that the learner solution generates signal data that matches the expected signal data within the specified tolerance:
Select Add Test > Signal data. This action adds a Signal Assessment block.
Connect a signal to the Signal Assessment block.
Click Capture Signal Data. The Signal source value updates to indicate the source block.
To check the captured signal data in a figure window, click Signal data captured.
Optionally, specify an absolute tolerance in the Tolerance box. When the learner solution uses a different approach than the reference solution, the tolerance can determine whether the test passes. For each time step, the test checks whether the learner’s signal data differs from the expected value by more than the specified absolute tolerance.
If you update the model, recapture the signal data. The signal data you capture is a snapshot that does not automatically update when you update the model.

Learners receive a plot of the signal requirement and a question about whether the signal meets the requirement.

For each task, you can test the data of only one signal.
Add Custom Test
To write a custom test using a MATLAB function:
Select Add Test > Custom.
In the Question box, enter the question for the learner.
Next to Function, click the hyperlink. The function opens in a Custom Test tab. When you have more than one custom test, the tab names include numbers for uniqueness.
In the function, implement custom logic that tests the learner solution.
The function can use the input argument
mdlfor the name of the solution model in quotes, such as"SolutionModel".The function must have an input argument, even if the input argument is unused.
The function must return whether the learner solution passes the test as numeric or logical
1(true) or0(false).
To check whether a custom test is free of errors, click Run Test.
Check whether the test is valid and whether your solution passes the test.
For example, suppose your solution has a
PID Controller block named Cruise Control with
one input signal, and you want to check that learners name the input signal
error. The custom test could be as follows.
function pass = customTest(mdl) ports = get_param(mdl+"/Cruise Control","PortHandles"); in1 = ports.Inport(1); signal = get_param(in1,"Name"); pass = (signal == "error"); end
After you run the test, you receive a message that says whether your solution passes the test.

Learners see only the question that you author. They do not see the function.

For
another example, suppose you want to check that learners add to the base workspace a
variable named k with a value of 5. The custom
test could be as follows.
function pass = customTest(mdl) k = evalin('base','k'); pass = (k == 5); end
If you set k to 5 in the base workspace and
then run the test, you receive a message that your solution passes the test.

Learners see the question that you author.
