build
Class: matlabtest.compiler.TestCase
Namespace: matlabtest.compiler
Syntax
Description
builds the deployed code artifact by using MATLAB®
Compiler SDK™ with the type buildResults
= build(testCase
,functionsToDeploy
,artifactType
)artifactType
from the MATLAB functions functionsToDeploy
in the equivalence test case
testCase
.
builds the deployed code artifact with the options and type specified by
buildResults
= build(testCase
,buildOptions
)buildOptions
.
preserves the build folder and its contents after a test failure.buildResults
= build(___,PreservingOnFailure=true)
Input Arguments
testCase
— Test case
matlabtest.compiler.TestCase
object
Test case, specified as a matlabtest.compiler.TestCase
object.
functionsToDeploy
— Files implementing MATLAB functions
string scalar | string array | char vector | cell array of character vectors
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"]
artifactType
— Artifact type to build
"dotNETAssembly"
| "javaPackage"
| "pythonPackage"
| "productionServerArchive"
| "cppSharedLibrary"
Artifact type to build, specified as "dotNETAssembly"
,
"javaPackage"
, "pythonPackage"
,
"productionServerArchive"
, or
"cppSharedLibrary"
.
buildOptions
— Build options
compiler.build.DotNETAssemblyOptions
object | compiler.build.JavaPackageOptions
| compiler.build.PythonPackageOptions
object | compiler.build.ProductionServerArchiveOptions
object | compiler.build.CppSharedLibraryOptions
object
Build options, specified as one of these objects:
compiler.build.DotNETAssemblyOptions
(MATLAB Compiler SDK)compiler.build.JavaPackageOptions
(MATLAB Compiler SDK)compiler.build.PythonPackageOptions
(MATLAB Compiler SDK)compiler.build.ProductionServerArchiveOptions
(MATLAB Compiler SDK)compiler.build.CppSharedLibraryOptions
(MATLAB Compiler SDK)
Output Arguments
buildResults
— Build results
compiler.build.Results
object
Build results, returned as a compiler.build.Results
(MATLAB Compiler SDK) object.
Examples
Generate and Test Python Package for Equivalence
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:
Builds the Python package from the
makesquare
functionExecutes the Python package with input set to
5
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.
Generate and Test Python Package with Additional Build Options
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 from
matlabtest.compiler.TestCase
. The test case in the
methods
block defines a test case that:
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 packageBuilds the Python package from the build options object
Executes the Python package with input set to
5
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.
Generate and Test Python Package for Equivalence with Additional Customizations
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 function
myAdd
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:
Builds a packaged that contains
makesquare
andmyAdd
Saves the build results object if the test fails
Verifies the result with an absolute tolerance
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
You cannot generate deployed code artifacts or test them for equivalence in MATLAB Online™.
Version History
Introduced in R2023aR2024b: Build deployable C++ shared libraries
Build deployable C++ shared libraries by specifying the artifactType
input argument as "cppSharedLibrary"
or by
specifying the buildOptions
input argument as a compiler.build.CppSharedLibraryOptions
(MATLAB Compiler SDK) object.
R2024a: Build deployable archives for MATLAB Production Server or other microservices
Build deployable archives for MATLAB
Production Server™ or other microservices by specifying the artifactType
input argument as "productionServerArchive"
or
by specifying the buildOptions
input argument as a compiler.build.ProductionServerArchiveOptions
(MATLAB Compiler SDK) object.
See Also
Classes
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)