You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Robot Framework是否支持验证指定时段内无事件发生的测试场景?

Robot Framework 是否支持验证指定时段内事件未发生的测试场景?

假设存在一个带有MQTT接口的灯光控制系统(例如Home Assistant),先看直观的日间模式测试用例:

connect to mqtt broker
publish "DAY" to topic mysystem/mode
subscribe to mysystem/lights/lamp1
publish "PRESS" to topic mysystem/buttons/button1
expect to receive message "ON" in topic mysystem/lights/lamp1

而夜间模式下,系统不应触发灯光开启,需要验证对应主题在指定时长内不会发布"ON"消息,测试逻辑如下:

connect to mqtt broker
publish "NIGHT" to topic mysystem/mode
subscribe to mysystem/lights/lamp1
publish "PRESS" to topic mysystem/buttons/button1
expect to not receive any messages at all in topic mysystem/lights/lamp1 (for X seconds wait period)

Robot Framework 完全支持这类「验证指定时段内某事件未发生」的测试场景,常见实现方式有两种:

  • 利用内置关键字实现
    借助BuiltIn库的Wait Until Keyword Does Not Succeed关键字,设置等待时长和要检查的操作。比如如果有一个Check Message Received关键字用于检测目标主题是否收到"ON"消息,可编写如下逻辑:

    Wait Until Keyword Does Not Succeed    X seconds    Check Message Received    mysystem/lights/lamp1    ON
    

    这段代码会在X秒内反复执行检查操作,若超时前始终未检测到目标消息,测试通过;反之若期间收到消息,测试失败。

  • 自定义等待+检查逻辑
    先调用Sleep等待指定时长,之后检查MQTT订阅的消息队列中是否存在目标主题的"ON"消息。如果队列无对应消息则测试通过,否则失败。示例逻辑如下:

    Sleep    X seconds
    ${messages}=    Get Messages From Topic    mysystem/lights/lamp1
    Length Should Be    ${messages}    0
    

内容的提问来源于stack exchange,提问作者hlovdal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 18:05:01