Main Content

polyspace.project.TestCaseRef Class

Namespace: polyspace.project

(Python) Manage test cases referenced by project

Since R2026a

Description

This Python® class contains information about a graphical test case that is saved in a .pstestd file, referenced by a Polyspace® Platform project. When you reference a .pstestd file from a project, it is called a test reference. Saving your graphical test cases in .pstestd files and referencing those files from one or more projects enables you to create a modular project structure that improves sharing and version control managed workflows. For more information about project structure, see Modularize Project by Using External Configurations, Test References, and External Stub Files.

To work with test references, use this class, which contains the name of the graphical test and the path to the .pstestd file, together with the polyspace.project.TestCase class, which contains the actual test case definition. You can also work with test references in the Polyspace Platform user interface.

To create and manage test cases that are owned by the project, use the polyspace.project.OwnedTestCase class.

Creation

Description

Import Test Case by Reference

testCaseRef = testSuite.TestCaseRefs.add(testCase, testCaseRefName) adds a reference from the test suite testSuite to testCase, where testCase is an existing polyspace.project.TestCase object or the path to a .pstestd file. The Name property of the resulting polyspace.project.TestCaseRef object is set to testCaseRefName. For more information on the polyspace.project.TestSuite object and its methods, see the description of the TestSuites property of the polyspace.project.Project class.

testCaseRef = testSuite.TestCaseRefs.add(testCaseRefObj) adds a reference to testCaseRefObj from the test suite testSuite and inherits the test case name. For more information on the polyspace.project.TestSuite object and its methods, see the description of the TestSuites property of the polyspace.project.Project class.

testCaseRef = testSuite.TestCaseRefs.add(testCaseRefObj, testCaseRefName) adds a reference to testCaseRefObj from the test suite testSuite. Use the testCaseRefName argument to set the Name property of the resulting testCaseRef object. For more information on the polyspace.project.TestSuite object and its methods, see the description of the TestSuites property of the polyspace.project.Project class.

Convert Test Case

testCaseRef = testSuite.TestCaseRefs.moveAsRef(ownedTestCaseObj,testFile) converts the existing ownedTestCaseObj in testSuite to a polyspace.project.TestCaseRef object and saves the graphical test case from ownedTestCaseObj in the file testFile.pstestd. After conversion, the project references the test case saved in testFile.pstestd. You can specify testFile as an absolute or relative path, where relative paths are considered relative to the location of the .psprjx project file. The resulting polyspace.project.TestCaseRef object has its Path property set to testFile and its Name property is inherited from the owned test case.

example

testCaseRef = testSuite.TestCaseRefs.moveAsRef(ownedTestCaseObj,testFile, testCaseRefName) converts the existing ownedTestCaseObj in testSuite to a polyspace.project.TestCaseRef object and saves the graphical test case defined in ownedTestCaseObj in the file testFile.pstestd. After conversion, the project references the test case saved in testFile.pstestd. You can specify testFile as an absolute or relative path, where relative paths are considered relative to the location of the .psprjx project file. The resulting polyspace.project.TestCaseRef object has its Path property set to testFile and its Name property is set to the testCaseRefName argument you provide.

example

Input Arguments

expand all

Test case to add a reference to from the test suite, specified as a polyspace.project.TestCase object or a path to an existing .pstestd file.

Name to assign the referenced test case, specified as a string. This name is assigned to the Name property of the polyspace.project.TestCaseRef object.

Existing testCaseRefObj to add a reference to from the test suite, specified as a polyspace.project.TestCaseRef object.

Existing owned test case to convert to a .pstestd file that is referenced by the project, specified as a polyspace.project.OwnedTestCase object.

Name of the .pstestd file to create when converting an existing owned test case to a test case reference, specified as a relative or absolute path. Relative paths are considered relative to the location of the .psprjx project file.

Properties

expand all

Name of the test case reference, specified as a string. If you do not specify a Name argument, the name defaults to that of the existing test case you are adding or converting.

Path to the .pstestd file where the test case reference is saved, specified as a string. All relative paths are considered relative to the location of the .psprjx project file.

Methods

expand all

Examples

collapse all

Modularize a Polyspace Platform project by converting an owned test case to a test reference. A test reference is a graphical test case saved in a .pstestd file that is referenced by the project.

Create the project, add your source files, and parse the code.

## Import modules
import polyspace.project
import polyspace.test
import os

## Create project
examples_path = os.path.join(polyspace.__install_path__, "polyspace", 
                            "examples", "doc_pstest", "python_api_test_authoring")
proj = polyspace.project.Project("testRefProject.psprjx")

## Add source files and include headers
proj.Code.Files.add(os.path.join(examples_path, "src", "algo.c"))
proj.Code.Files.add(os.path.join(examples_path, "src", "saturate.c"))
proj.IncludePaths.add(os.path.join(examples_path, "src"))

## Save project and parse code
proj.save()
codeInfo = polyspace.project.parseCode(proj)

Next, add a test suite and create a new graphical test.

# Create test suite and test case
suiteSaturateValue = proj.TestSuites.create("checkSaturateValueTests")
simpleTest = suiteSaturateValue.TestCases.create("saturate_value_simpleTest")

# Create test step for a simple test
functionSaturateValue = codeInfo.getFunctionBySignature("int saturate_value(int)")
simpleStep = simpleTest.TestSteps.createTabular("saturate_value_simpleStep", functionSaturateValue)

# Update inputs and assessments that are automatically created
simpleStep.Inputs["value"].Value = "2"
simpleStep.Assessments["pst_call_out"].Value = "2"

# Create a new assessment to check that the global variable minValue is unchanged
minValue = codeInfo.getGlobalByName("minValue")
simpleStep.Assessments.create(minValue)
simpleStep.Assessments["minValue"].Value = "-2"

Build and run your test.

res = polyspace.test.run(proj)
res.generateHTMLReport("testReport")

Convert your graphical test case to a test reference. Then, save the project and build and run your test again.

# Convert the saturate_value_simpleTest to a test case reference
testRef = suiteSaturateValue.TestCaseRefs.moveAsRef(simpleTest, "testRefFile.pstestd", "simpleTestRef")

# Save the project and build and run the test again
proj.save()
status = polyspace.test.build(proj)
res = polyspace.test.run(proj)
res.generateHTMLReport("testRefReport")

Version History

Introduced in R2026a