无论如何我们可以使用 ShouldMatchers 在 Scalatest 中给出两个条件

编程入门 行业动态 更新时间:2024-10-12 18:20:09
本文介绍了无论如何我们可以使用 ShouldMatchers 在 Scalatest 中给出两个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我怎么能做这样的事情?测试时检查两个条件

How can I do something like this? Check for two conditions while testing

// b is Option[Array[Int]] b should be ('empty) || b.get should be ('empty)

我想使用 ShouldMatchers 而不是 assert 来实现,因为 ShouldMatchers 是 scalatest 的一部分.

I want to do it using ShouldMatchers instead of assert, since ShouldMatchers is part of scalatest.

推荐答案

你应该可以做到

val b: Option[Array[Int]] = ??? b should (be ('empty) or be (Some(Array.empty[Int]))

请参阅 scalatest 手册的这一部分:逻辑表达式

See this section of the scalatest manual: Logical Expressions

更多推荐

无论如何我们可以使用 ShouldMatchers 在 Scalatest 中给出两个条件

本文发布于:2023-10-08 14:59:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472966.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   无论如何   条件   两个   ShouldMatchers

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!