无论如何我们可以使用 ShouldMatchers 在 Scalatest 中给出两个条件 [英] Is there anyway we can give two conditions in Scalatest using ShouldMatchers

查看:64
本文介绍了无论如何我们可以使用 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 中给出两个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆