Main Content


Class: matlabtest.coder.TestCase
Namespace: matlabtest.coder

Create test case for interactive use

Since R2023a



testCase = matlabtest.coder.TestCase.forInteractiveUse creates an interactive equivalence test case to test C/C++ code that was generated by using MATLAB® Coder™. The returned matlabtest.coder.TestCase reacts to qualifications by printing messages for passing and failing events.



To learn about attributes of methods, see Method Attributes.


expand all

This example shows how to generate C code from a MATLAB function and test for equivalence by using an interactive equivalence test.

The function myAdd takes two numbers as inputs, adds them together, and outputs the result.

function y = myAdd(a,b) %#codegen
y = a+b;

Create a test case for interactive equivalence testing.

testCase =  matlabtest.coder.TestCase.forInteractiveUse;

Generate C code from myAdd with inputs set to (1,2).

buildResults = build(testCase,"myAdd",Inputs={1,2});
[Verbose] Diagnostic logged (2023-01-09 10:32:20): ### Generating code for "myAdd.m" (MEX configuration)
[Verbose] Diagnostic logged (2023-01-09 10:32:23): Code generation successful.

Execute the generated C code with the build-time inputs.

executionResults = execute(testCase,buildResults);
Assertion passed.
[Verbose] Diagnostic logged (2023-01-09 10:32:23): ### Executing "myAdd_mex.mexw64" with specified run-time inputs
[Verbose] Diagnostic logged (2023-01-09 10:32:23): Execution successful.

Verify that the execution of the C code matches the execution of the MATLAB function with the same inputs.

Verification passed.

Version History

Introduced in R2023a