unit-testing - 如何进行仅在断言失败时通过的测试?

标签 unit-testing testing verilog system-verilog

我有一个模块,当检测到不应该出现的先决条件时,它有一个断言。当我为模块提供无效输入时,如何编写基于此断言失败的测试通过?

过去,我曾使用 Verilog PLI 完成此类工作。我正在学习 SystemVerilog,如果可能的话,我更愿意使用一些 Verilog 或 SV 结构并避免运行单独的程序。

最佳答案

我认为您的想法是错误的。

I have a module that has an assert when a pre-condition that should never occur is detected. How can I write a test that passes based on this assert failing when I give the module invalid inputs?

这听起来很困惑。如果模块对给定的输入做了正确的事情,则测试应该通过。如果模块做出正确的响应,则为模块提供无效输入不应导致测试失败。正确的做法可能是标记错误、引发中断或可能只是忽略输入。

因此,您永远不需要要求测试失败。

我想你的意思是:

I want to test a module with "invalid" stimulus, and I want to make sure the module notices (e.g. by flagging an error)

在这种情况下断言变成:

assert @some_event (invalid_input |=> error_caught);

然后您使用覆盖率来确保测试导致断言在某个时间点完成。

关于unit-testing - 如何进行仅在断言失败时通过的测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18343502/

相关文章:

java - 如何对客户端服务器代码进行单元测试

java - RxJava : How to unit test that an Observable is observed on and subscribed on the right scheduler?

verilog - 算术移位充当逻辑移位,无论有符号变量如何

verilog - x和z之间的差异

java - 有没有办法在不阻塞线程的情况下暂停单元测试

java - 测试数据工厂方法是危险还是有益?

java - Mockito 1.9.5 导致 NullPointerException

c# - Moq 模拟泛型和表达式函数

ruby-on-rails - 如何减慢本地 ruby​​ 网络服务器上的文件下载速度?

parsing - Verilog 门级解析器