Main Content

createTemporaryFolder

Class: matlabtest.coder.TestCase
Package: matlabtest.coder

Create temporary folder in generated C/C++ code equivalence test

Since R2023a

Description

example

folder = createTemporaryFolder(testCase) creates a temporary folder for the generated C/C++ code equivalence test case, testCase and returns the full path to the folder as a character vector. When the test case goes out of scope, the testing framework removes the folder.

Input Arguments

expand all

Test case, specified as a matlabtest.coder.TestCase object.

Output Arguments

expand all

Full path to the temporary folder, returned as a character vector.

Examples

expand all

This example shows how to generate C code to a temporary folder and test for equivalence.

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

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

This class definition file defines an equivalence test case that inherits from matlabtest.coder.TestCase. The test class:

  1. Defines a class-level property called Folder to contain the folder path

  2. Defines a method-level setup to create the temporary folder

  3. Defines a test method that:

    1. Builds C code from the myAdd function with inputs set to (1,2) to the temporary folder location

    2. Executes the C code with the build-time inputs

    3. Verifies the execution of the C code against the execution of the MATLAB® function myAdd with the same inputs

classdef tEquivalence < matlabtest.coder.TestCase

    properties
        Folder;
    end

    methods (TestMethodSetup)
        function setup(testCase)
            testCase.Folder = createTemporaryFolder(testCase);
        end
    end

    methods(Test)
        function tMyAdd(testCase)
            buildResults = build(testCase,"myAdd",Inputs={1,2},Folder=testCase.Folder);
            executionResults = execute(testCase,buildResults);
            verifyExecutionMatchesMATLAB(testCase,executionResults)
        end
    end
end

Run the tMyAdd test.

runtests("tEquivalence", ...
    procedureName="tMyAdd")
Running tMyAdd
..
Done tMyAdd
__________


ans = 
  TestResult with properties:

          Name: 'tMyAdd/tMyAdd'
        Passed: 1
        Failed: 0
    Incomplete: 0
      Duration: 2.6670
       Details: [1×1 struct]

Totals:
   1 Passed, 0 Failed, 0 Incomplete.
   2.667 seconds testing time.

Version History

Introduced in R2023a