Unit testing helper or non-interface traits in Scala

后端 未结 2 1775
情话喂你
情话喂你 2020-12-31 06:29

This question is about dealing with testing of classes which mix in non-interface traits, that is traits containing some functionality. When testing, the class functionality

2条回答
  •  孤城傲影
    2020-12-31 07:11

    How about:

    val helpers = new HttpHelpers {
      //override or define stuff the trait needs to work properly here
    }
    
    helpers.someMethodToTest
    

    Look, Ma, no intermediate traits and mocking libraries needed!

    I do that all the time for my traits and I've been pretty happy with the result.

提交回复
热议问题