polyspace.test.TestCaseResult Class
Namespace: polyspace.test
Description
This Python® class contains test results for a specific test case in a C/C++ test suite.
Creation
Description
testCaseResult = loads the results of test suite number testSuiteResult.TestCaseResults[testCaseIndex]testSuiteIndex:
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.
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 suite or test 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 suite execution, for example, |
ExecutionTime | Floating-point value | Time taken for test suite 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 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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)