简体   繁体   中英

How to mock a Scala Seq?

I basically need to test an edge-case where I have a Seq[Foo] with 100 Foo objects. Instead of manually initializing 100 unique Foo objects and adding them to a Seq, is there some functionality of mockito I can use?

What I'm basically trying to do is: 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:

object Foo
Seq.fill(100)(Foo)

This will fill the Seq with 100 Foo objects. I don't see any benefit to using Mockito for something like this.

Read more about it in the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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