简体   繁体   English

如何模拟 Scala Seq?

[英]How to mock a Scala Seq?

I basically need to test an edge-case where I have a Seq[Foo] with 100 Foo objects.我基本上需要测试一个边缘情况,其中我有一个带有 100 个 Foo 对象的 Seq[Foo]。 Instead of manually initializing 100 unique Foo objects and adding them to a Seq, is there some functionality of mockito I can use?不是手动初始化 100 个唯一的 Foo 对象并将它们添加到 Seq,我可以使用 mockito 的一些功能吗?

What I'm basically trying to do is: val mockSeq = mock(Seq) when(mockSeq).length.thenReturn(100)我基本上想做的是: val mockSeq = mock(Seq) when(mockSeq).length.thenReturn(100)

As cchantep says , you're probably better off just creating a Seq and filling it, something like this: 正如 ccantep 所说,您最好创建一个 Seq 并填充它,如下所示:

object Foo
Seq.fill(100)(Foo)

This will fill the Seq with 100 Foo objects.这将用 100 个 Foo 对象填充 Seq。 I don't see any benefit to using Mockito for something like this.我认为将 Mockito 用于这样的事情没有任何好处。

Read more about it in the docs . 在文档中阅读更多关于它的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM