score:0

You can create a declaration of a class that extends the trait in your test and then mock that class:

class TestHtmlConverter extends HtmlConverter

/* other code elided */
val htmlConverter = mock[TestHtmlConverter]
htmlConverter.getContentFromUrl(/* ... */) returns "<html />"

score:0

You can structure your method differently to avoid needing the mock at all.

class HtmlConverter {
    val retriever = new HtmlRetriever
    def convertFromUrl(url:String) = {
         val content = retriever.getContentFromUrl(url)
         convert(content)
    }
    def convert(content: ContentFromUrl) = {
        // convert
    }
}

Then you can simply test convert directly. A different suite of tests can cover retriever, and your convertFromUrl method is now simple enough to not need a direct unit test.


Related Query

More Query from same tag