unit testing - Mocking a val of a trait with scala-mock -


i'd mock val of trait. example, in code, mock val baz:

trait foo {   def bar(): int   val baz: int }  val foomock = mock[foo] (foomock.bar _).expects().returning(5) (foomock.baz _).expects().returning(6) //doesn't compile  dosomething(foomock) 

to solve in test, i've extended foo, , implemented baz in following manner:

trait footest extends foo {   override val baz: int = 5 }  val foomock = mock[footest] (foomock.bar _).expects().returning(6)  dosomething(foomock) 

but ugly, , hoping there more standard way of doing scala mock.

i've seen answer question, requires changing val def in trait, , i'd keep baz val

this isn't supported scalamock's macro-based mocks things stand. 1 of things hope address when scala.meta becomes available.

if want track this, might want follow:

https://github.com/paulbutcher/scalamock/issues/40

there option might of interest - scalamocks's proxy-based mocks support mocking vals. example, see scalamock test suite:

https://github.com/paulbutcher/scalamock/blob/master/core_tests/src/test/scala/com/paulbutcher/test/proxy/proxymocktest.scala#l163


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -