gpt4 book ai didi

ScalaTest 抛出通过测试异常消息

转载 作者:行者123 更新时间:2023-12-04 11:16:58 29 4
gpt4 key购买 nike

为了测试我的代码是否抛出预期的异常,我使用以下语法:

  an [IllegalArgumentException] should be thrownBy(Algorithms.create(degree))

有什么方法可以测试抛出的异常是否包含预期的消息,例如:
  an [IllegalArgumentException(expectedMessage)] should be thrownBy(Algorithms.create(degree)) -- what doesn't compile 

?

最佳答案

Documentation :

the [ArithmeticException] thrownBy 1 / 0 should have message "/ by zero"

并使用该示例:
 the [IllegalArgumentException] thrownBy(Algorithms.create(degree)) should have message expectedMessage

关于ScalaTest 抛出通过测试异常消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31215768/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com