scala - Stackable traits for mocking shared state -


I have some components that have mixed symptoms, which include system logic (caching, service etc.). And the tests need to fool this argument. It is very easy ...

But I need to test the bundles of components with the same cache and I can not share some global cache. Therefore, my solution is:

Code:

  The attribute component class provides components with cache with MyComponent1 services {...} class cache with MyComponent2 services Provides components with {...} attribute cache {private val _cache = ... def query (...) = ...}   

in test API:

  Specialty CacheMock Cache Map (Private [Package] Override Def Query (...) = _cache.get (...)} Case Class Config (Cash Make: Cache) on var _cache = null // ) Specialty TestAPI {val componentCreator: = & gt; List [Component] DEF Test (Configuration: config) = {val instance = front of the contractor creator examples {Case Mash: CacheMock => mocked._cache = config.cache mock case _ = & gt;} Example:}   

In tests:

  Test API in class test {def componentCreator = list (New MyComponent1 with CashMock, New MyComponent2 with CashMock) Test (Config 1 (Mac)) Test ( Configuration (Mac 2))}   

Component of the component optional solution Capture: cache = & gt; The list [component], but it's a bit ugly.

So is there a better solution, which can provide a simple DSL (without boilerplate), but without the unexplained version? Or framework that can solve similar problems?

does not compile as your code, but it should be understood in my opinion:

  Class TestMyComponent1 (Protected _cache: Cache) increases MyComponent1 with CacheMock class TestMyComponent2 (protected _cache: cache) MyComponent2 spreads with cache-mail attribute, secures CacheMock cache {protected val _cache: Test API {def componentCreator = List (New TestMyComponent1 (mock1), New TestMyComponent2 (mock2)} in Cache override def query (...) = _cache.get (...)} test    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -