polyspace.test.TestCaseResult Class
R2026bNamespace: polyspace.test
Description
This Python® class contains test results for a specific test case in a C/C++ test suite.
Creation
Syntax
Description
testCaseResult = returns the result of the test case named testResults.getResults(SuiteName, TestName)[0]TestName in suite SuiteName:
From a
polyspace.test.TestResultsobjecttestResults.To a
polyspace.test.TestCaseResultobjecttestCaseResult.
Here, SuiteName is the name of the test suite and TestName is the name of the test case, both specified as strings.
If the test with name is a parametrized test, TestNamegetResults returns multiple results as a list of polyspace.test.TestCaseResult objects. You can access the results for each iteration of the parametrized test by indexing into this list.
testCaseResult = loads the results of test case number testSuiteResult.TestCaseResults[testCaseIndex]testCaseIndex:
From a
polyspace.test.TestSuiteResultobjecttestSuiteResult.To a
polyspace.test.TestCaseResultobjecttestCaseResult.
Here, testCaseIndex is the index of the test case specified as an integer starting from 0.
Input Arguments
Name of the test suite containing the test case, specified as a string.
To find the names of all test suites in a results object
res, enter the following:suite_names = [s.Name for s in res.TestSuiteResults]To find the names of all test suites whose names begin with
"Sensor", enter the following:suite_names = [s.Name for s in res.TestSuiteResults if s.Name.startswith("Sensor")]
Name of the test case whose results you want to retrieve, specified as a string.
To find the names of all test cases along with their suite names in a results object
res, enter the following:suite_and_test_names = [(s.Name, tc.Name) for s in res.TestSuiteResults for tc in s.TestCaseResults] for suite_name, test_name in suite_and_test_names: print(suite_name, test_name)To find the names of all test cases whose names begin with
"Sensor"along with their suite names, enter the following:suite_and_test_names = [(s.Name, tc.Name) for s in res.TestSuiteResults for tc in s.TestCaseResults if tc.Name.startswith("Sensor")] for suite_name, test_name in suite_and_test_names: print(suite_name, test_name)
Properties
Name of test case.
Overall execution status of the test case, specified as a polyspace.test.DetailedStatusInfo object with the following properties:
| Property | Values | Description |
|---|---|---|
Failed | True or False | The value of this property is In all other cases, the value is |
Incomplete | True or False | The value of this property is In all other cases, the value is |
VerifyFail | True or False | The value of this property is For more information on |
AssertFail | True or False | The value of this property is For more information on |
AssumeFail | True or False | The value of this property is For more information on |
Exception | True or False | The value of this property is |
NotRun | True or False | The value of this property is Otherwise, the value is |
Crash | True or False | The value of this property is |
ExpectFail | True or False | The value of this property is |
File containing test definition.
Line number where test definition begins. This is the line containing the PST_SIMPLE_TEST, PST_TEST, or PST_TEST_CONFIG macro (depending on whether your test case is a simple test, a test in a named suite without a configuration, or a test in a named suite with a configuration).
Timing of test case execution and timestamp of execution, specified as a polyspace.test.TimingInfo object with the following properties:
| Property | Value | Description |
|---|---|---|
Timestamp | datetime.datetime value | Time stamp of the beginning of test case execution, for example, |
ExecutionTime | Floating-point value | Time taken for test case execution in seconds (up to millisecond precision). |
Total number of assessments in the test. This number includes passing and failing assessments.
Number of passing assessments in the test case.
Number of failing assessments in the test case.
Result details for assessments in the test case, returned as a list of polyspace.test.AssessmentResult objects with one object per assessment.
For more information, see polyspace.test.AssessmentResult.
Result details for passing assessments in the test case, returned as a list of polyspace.test.AssessmentResult objects with one object per passing assessment.
For more information, see polyspace.test.AssessmentResult.
Result details for failing assessments in the test case, returned as a list of polyspace.test.AssessmentResult objects with one object per failing assessment.
For more information, see polyspace.test.AssessmentResult.
Messages emitted during test execution that are not related to assessments. For instance, an issue unrelated to assessments can occur during test execution and a warning message might be emitted The message is specified as a polyspace.test.Message object with the following properties:
| Property | Description |
|---|---|
Phase | The value can be one of the following:
|
Type | The value can be one of the following:
|
Msg | Actual content of the message. |
Events that occurred during test execution specified as a heterogeneous list of polyspace.test.Message and polyspace.test.AssessmentResult objects. The sequence of objects in the list represents the actual sequence in which the events occurred.
For instance, suppose that the body of a test contains one assessment but during test execution, a warning message is emitted before the assessment runs. The Events property contains two objects:
Events[0]is apolyspace.test.Messageobject that contains details of the warning message. For more information on this object, see Messages.Events[1]is apolyspace.test.AssessmentResultobject that contains details of the assessment result. For more information on this object, see AssessmentResults.
The Events property allows you to see the sequence in which the events occurred. If you are not interested in the sequence, use the Messages property to check for warnings and other messages, and the AssessmentResults property to retrieve the results of assessments.
Examples
This example shows how to retrieve results for a specific test case by name using the getResults method.
In general, you generate and manage Polyspace®
Test™ results by using classes from the polyspace.project and polyspace.test modules. Before starting, make sure you can import these modules on a Python shell or in a Python script without errors. For more information, see Set Up Python API for Polyspace.
Open the shipped example project, build, and run tests:
import polyspace.project
import polyspace.test
import os
proj = polyspace.project.Project(os.path.join(
polyspace.__install_path__, "polyspace", "examples",
"pstest", "Getting_Started_Example", "Demo_C_PS_Test.psprjx"))
polyspace.test.build(proj)
res = polyspace.test.run(proj)Retrieve the result of the test case named "addLatestReading_test_1" in suite "setStateTests":
tcRes = res.getResults("setStateTests", "addLatestReading_test_1")[0]
print(f"Test Case: {tcRes.Name}, Failed: {tcRes.Status.Failed}")This example shows to print the names of failing test cases after running tests in a project.
In general, you generate and manage Polyspace
Test results by using classes from the polyspace.project and polyspace.test modules. Before starting, make sure you can import these modules on a Python shell or in a Python script without errors. For more information, see Set Up Python API for Polyspace.
Import the required modules:
import polyspace.project import polyspace.test import osAdd source files and xUnit test files to a project. This example uses some example source and test files available with a Polyspace Test installation. Instead, you can use your own sources and tests.
examples_path = os.path.join(polyspace.__install_path__, "polyspace", "examples", "pstest", "Getting_Started_Example") polyspaceProject = polyspace.project.Project("newProject") polyspaceProject.Code.Files.add(os.path.join(examples_path, "sources", "utils.c")) polyspaceProject.IncludePaths.add(os.path.join(examples_path, "includes")) polyspaceProject.Tests.Files.add(os.path.join(examples_path, "tests", "test.c"))Run the tests added to the project.
res = polyspace.test.run(polyspaceProject)Print the names of failing test cases (along with their suite names).
for suiteIndex in range(len(res.TestSuiteResults)): # Read result of test suite resTestSuite = res.TestSuiteResults[suiteIndex] if(resTestSuite.Status.Failed): for testIndex in range(len(resTestSuite.TestCaseResults)): # Read result of test case resTestCase = resTestSuite.TestCaseResults[testIndex] if(resTestCase.Status.Failed): print(resTestSuite.Name + "/" + resTestCase.Name)Alternatively, you can simply iterate through the test suites and cases as follows:
for resTestSuite in res.TestSuiteResults: if resTestSuite.Status.Failed: for resTestCase in resTestSuite.TestCaseResults: if resTestCase.Status.Failed: print(f"{resTestSuite.Name}/{resTestCase.Name}")If you use the example source and test files, you should see the suite and test name
updateStateTests/addLatestReading_test_1_failprinted.
Version History
Introduced in R2024b
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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)