Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

将测试用例链接到需求

如果您有 Simulink® Test™ 和 Requirements Toolbox™,则可以将需求链接到 Simulink 测试用例。通过将需求链接到测试,您可以使用需求验证状态来跟踪验证进度并验证需求的实现是否与预期相符。

此示例说明如何将测试用例链接到与汽车巡航控制系统的控制器模型关联的需求。运行测试后,您可以在需求编辑器中查看验证状态。

打开工程文件

打开 CruiseRequirementsExample 工程,其中包含汽车巡航控制系统的需求、模型和测试。然后,打开 crs_controller 模型。

openProject("CruiseRequirementsExample");
open_system("models/crs_controller")

在 MATLAB® 中,打开包含要链接的测试的测试文件。在工程窗格的 tests 文件夹中,右键点击测试管理器中的 DriverSwRequest_Tests.mldatx 测试文件并选择打开来打开该文件。测试用例使用 crs_controller 模型作为在测系统。许多测试用例都链接到 crs_req_func_spec 需求集中的需求。

The DriverSwRequest_Tests test file is shown in the Test Browser. Its single test suite and eight test cases are shown.

在此示例中,您需要将测试用例链接到 crs_req_func_spec 需求集中的需求。打开需求编辑器。在 App 中,选择需求编辑器

The Requirements Editor shows the crs_req_func_spec requirement set. Its four top-level requirements and top-level justification are collapsed.

当您打开 crs_controller 模型时,Requirements Toolbox 已加载了 crs_req_func_spec 需求集,因为文件之间有链接。通过点击“刷新”按钮 refresh_16.png,确保需求编辑器分析的是验证链接的功能需求。

将需求链接到测试

将具有摘要 Resume switch detection 的需求链接到名为 Resume button 的测试用例。要创建链接,请执行以下操作:

  1. 测试管理器中,点击 Resume button

  2. 需求编辑器中,选择具有索引 1.7 的需求。

  3. 链接部分点击添加链接 > 从所选测试用例链接

指向测试用例的链接将显示在右窗格的链接下。

Requirement 1.7 is selected in the Requirements Editor. The Properties section is collapsed. Its two implementation links to Simulink blocks and verification link to the Resume button test are shown.

点击 Resume button 链接以导航到测试管理器中的测试。

运行测试并查看验证状态

运行 DriverSwRequest_Tests 测试文件中的测试。在测试管理器测试浏览器窗格中,选择 DriverSwRequest_Tests 测试文件。点击运行

结果和工件窗格显示七个测试通过,一个测试失败。在结果和工件窗格中,展开测试运行的结果。Cancel button 测试失败。

The results of the test run are shown in the Results and Artifacts pane. Seven of the tests passed. The Cancel button test is the only failed test.

需求编辑器中查看链接到测试的需求的需求验证状态。在需求编辑器视图部分中,点击 > 验证状态。有些需求没有包含测试,有些需求已进行了充分验证。已验证列中的状态条显示了有验证链接的子需求的比例。相应颜色表示通过、失败或未运行的测试的比例。

The requirements verification status for the requirement set is displayed in the Requirements Editor. Requirement 1.7 is selected and the verification status bar is green, indicating that it is verified.

在此示例中,验证状态显示链接到需求 1.7 的测试通过,而链接到 Cancel Switch Detection 的测试失败。有些需求经过部分验证,因为子需求尚未验证,例如需求 1.8。要查看子需求的摘要,请指向父需求的验证状态条。其他需求未经过验证,因为它们未链接到测试用例。

导航到需求 1.7 的测试结果。选择该需求,然后在右窗格的链接下的 Resume button 旁边,点击“已通过”图标 。所链接测试的测试结果将在测试管理器中打开。

相关主题