matlabtest.compiler.TestCase.build - Generate deployed code artifacts in equivalence tests - MATLAB (original) (raw)

Class: matlabtest.compiler.TestCase
Namespace: matlabtest.compiler

Generate deployed code artifacts in equivalence tests

Since R2023a

Syntax

Description

[buildResults](#mw%5F833e8cc0-77cb-47d2-90bd-a968accd6eba) = build([testCase](#mw%5F40689a3e-ad9b-4ee9-9f19-c1bbdc5dfdde%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[functionsToDeploy](#mw%5Fb2bbd1c0-6b01-4865-86d5-97ff479b7766),[artifactType](#mw%5Fa327f26e-a19c-4985-8c5f-8b9157302ae3)) builds the deployed code artifact by using MATLAB® Compiler SDK™ with the type artifactType from the MATLAB functions functionsToDeploy in the equivalence test casetestCase.

example

[buildResults](#mw%5F833e8cc0-77cb-47d2-90bd-a968accd6eba) = build([testCase](#mw%5F40689a3e-ad9b-4ee9-9f19-c1bbdc5dfdde%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[buildOptions](#mw%5Fd2f827a6-ad0c-4d76-bd8a-9ee2d157c5b3)) builds the deployed code artifact with the options and type specified bybuildOptions.

example

[buildResults](#mw%5F833e8cc0-77cb-47d2-90bd-a968accd6eba) = build(___,PreservingOnFailure=true) preserves the build folder and its contents after a test failure.

example

Input Arguments

expand all

Files implementing MATLAB functions, specified as a string scalar, a string array, a character vector, or a cell array of character vectors. File paths can be relative to the current working directory or absolute. Files must have a .m extension.

Example: "makesquare.m"

Example: ["makesquare.m","myadd.m"]

Artifact type to build, specified as "dotNETAssembly","javaPackage", "pythonPackage","productionServerArchive", or"cppSharedLibrary".

Output Arguments

Examples

expand all

This example shows how to generate a Python® package from MATLAB source code and test for equivalence by using MATLAB Compiler SDK.

The function makesquare generates an_n_-by-n matrix:

function y = makesquare(x) y = magic(x); end

This class definition file defines an equivalence test case that inherits from matlabtest.compiler.TestCase. The test case in the methods block defines a test case that:

  1. Builds the Python package from the makesquare function
  2. Executes the Python package with input set to 5
  3. Verifies the execution of the Python package against the execution of the MATLAB function makesquare with the same input

classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) buildResults = build(testCase,"makesquare.m", ... "pythonPackage"); executionResults = execute(testCase,buildResults,{5}); verifyExecutionMatchesMATLAB(testCase,executionResults); end end end

Run the pythonEquivalence test.

runtests("tDeployment", ... ProcedureName="pythonEquivalence")

Running pythonEquivalence .. Done pythonEquivalence


ans =

TestResult with properties:

      Name: 'tDeployment/pythonEquivalence'
    Passed: 1
    Failed: 0
Incomplete: 0
  Duration: 93.1237
   Details: [1×1 struct]

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

This example shows how to generate a Python package with additional build options from MATLAB source code and test for equivalence by using MATLAB Compiler SDK.

The function makesquare generates an_n_-by-n matrix:

function y = makesquare(x) y = magic(x); end

This class definition file defines an equivalence test case that inherits frommatlabtest.compiler.TestCase. The test case in themethods block defines a test case that:

  1. Defines a compiler.build.PythonPackageOptions (MATLAB Compiler SDK) object that specifies the function to deploy, the package name, and provides additional files to include in the package
  2. Builds the Python package from the build options object
  3. Executes the Python package with input set to 5
  4. Verifies the execution of the Python package against the execution of the MATLAB function makesquare with the same input

classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase)

        buildOpts = compiler.build.PythonPackageOptions( ...
            "makesquare.m");
        buildOpts.PackageName = "PackageUnderTest";
        buildOpts.AdditionalFiles = "makesquareData.mat";

        buildResults = build(testCase,buildOpts);
        executionResults = execute(testCase,buildResults,{5});
        verifyExecutionMatchesMATLAB(testCase,executionResults);
    end
end

end

Run the pythonEquivalence test.

runtests("tDeployment", ... ProcedureName="pythonEquivalence")

Running pythonEquivalence .. Done pythonEquivalence


ans =

TestResult with properties:

      Name: 'tDeployment/pythonEquivalence'
    Passed: 1
    Failed: 0
Incomplete: 0
  Duration: 93.1237
   Details: [1×1 struct]

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

This example shows how to generate a Python package from MATLAB source code and test for equivalence by using MATLAB Compiler SDK.

The function makesquare generates an_n_-by-n matrix and the functionmyAdd takes two inputs and adds them together:

function y = makesquare(x) y = magic(x); end

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

This class definition file:

classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) functionsToDeploy = ["makesquare.m","myAdd.m"]; buildResults = build(testCase,functionsToDeploy, ... "pythonPackage",PreservingOnFailure=true);
preserveOnFailure=true; executionResults = execute(testCase,buildResults,{5}, ... "makesquare",PreservingOnFailure=preserveOnFailure); verifyExecutionMatchesMATLAB(testCase,executionResults, ... AbsTol=0.0001); end end end

Run the pythonEquivalence test.

runtests("tDeployment", ... ProcedureName="pythonEquivalence")

Running pythonEquivalence .. Done pythonEquivalence


ans =

TestResult with properties:

      Name: 'tDeployment/pythonEquivalence'
    Passed: 1
    Failed: 0
Incomplete: 0
  Duration: 93.1237
   Details: [1×1 struct]

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

Limitations

Version History

Introduced in R2023a