Skip to content
0:00 / 0:00

#scala#mocking#unittesting

Mocks & stubs by Ken Scambler

MelbJVM

984 subscribers • 1 video on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Ken Scambler
  • An opinion. It argues one side of a question engineers disagree on.

Intermediate. Assumes working knowledge.

15K views11 years ago2 recommendations

Software designTools and practiceTestingDesign patternsFunctional programming

Ken Scambler argues that mocks and stubs can be avoided through better software design and functional programming principles.

Mocks & stubs are sadly ubiquitous, but in almost every case their use can be avoided through a better design of the underlying software. Ken will go through some of the common patterns, and how to design them away. Themes: Functional programming, separation of concerns, modularity. Ken Bio: Ken Scambler is a FP enthusiast and Scala developer based in Melbourne. Long years in the Java mines have pushed his views on type safety and functional purity to outright bigotry. He is a co-organizer of the Melbourne Scala User Group, and has a pet rabbit.

Why it's here

2 people recommend this

What people say. Recommended as an excellent explanation of how to design away the need for mocking external services.

Moments people linked to

u/tpolecatTypelevelin r/scala • Recommends

On “Functional way of simulating external services/APIs without resorting to mocking?”

The general strategy is to talk about the *intent* to interact with an external service, which allows you to do much of your testing in these terms; i.e., you usually don't need to test that the email was actually sent, you need to test that the *request* to send an email contains the correct information, which shrinks the surface area of your integration testing. This talk by Ken Scambler explains this strategy very well I think. A generalization of this idea is to abstract the meaning out of your program using `Free`, and providing multiple interpreters. This allows you to swap out production logic for test logic to simulate unusual failures and so on. It's kind of like mocking in spiri…

u/enpassant2in r/scala • Recommends

On “Plain Functional Programming by Martin Odersky”

I think passing around plain old values is simpler, for example: https://github.com/enpassant/miniatures/blob/master/src/main/scala/plainFP/Config.scala "If we have to pass all these config parameters everywhere" (video at 20:22). I think this is a design flaw, that is passing unnecessary state everywhere. For example, readName method depend on Config object (unnecessary state of Config.age). There is a very good talk about it ("clumsy input") by Ken Scambler: link to this video I think the functional DSL solution is simpler than with implicit: https://github.com/enpassant/miniatures/blob/master/src/main/scala/plainFP/Table.scala
1View on Reddit