【问题标题】:Scalatest with and express for type checkingScalatest 和 express 用于类型检查
【发布时间】:2016-06-27 20:39:08
【问题描述】:

我想测试类型包含:

trait admin {}
trait manager {}

class User extends admin with manager {}

但我无法使用以下表达式进行扩展:

new User shouldBe (a [admin] and a [manager])

有没有办法在对象检查上应用逻辑表达式?

最新版本:2.2.4

【问题讨论】:

    标签: scala scalatest


    【解决方案1】:
    trait Admin
    trait Manager
    
    class User extends Admin with Manager
    

    parens 有点难看,但如果你想使用and,这很有效。

    new User should (be (an [Admin]) and be (a [Manager]))
    

    【讨论】:

      【解决方案2】:

      在 2 个语句中测试它们怎么样?

      new User shouldBe an [admin] new User shouldBe a [manager]

      顺便说一句,我认为 trait 的名称更常见的是 PascalCase

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-10
        • 2016-10-10
        • 2010-11-02
        • 1970-01-01
        • 1970-01-01
        • 2015-01-29
        • 1970-01-01
        相关资源
        最近更新 更多