I was reading an article by Dino Esposito on how to test AsyncConrollers in ASP.NET MVC and in there he uses the "Humble Object" pattern, without going into much detail.
I haven't had much luck Googling around either.
So, what is the Humble Object pattern? When would it be useful?
There is a thorough description at xunitpatterns.com.
Basically, you pull all the logic into a separate object which you can easily test - and your "Humble Object" becomes a wrapper around your testable object; it's just that the humble object also has dependencies on things that are difficult to test, like async services or GUI classes. The idea being to leave so little actual logic in the humble object that you don't need to test it, and so don't need to deal with testing the difficult to test dependency.
Humble Object pattern is mentioned in the book - Clean Architecture: A Craftsman's Guide to Software Structure and Design by Uncle Bob, Chapter 23 - PRESENTERS AND HUMBLE OBJECTS (https://learning.oreilly.com/library/view/clean-architecture-a/9780134494272/ch23.xhtml).
This pattern is applied at the boundaries of the system, where things are often difficult to test, in order to make them more testable. We accomplish the pattern by reducing the logic close to the boundary, making the code close to the boundary so humble that it doesn't need to be tested. The exctacted logic is moved into another class, decoupled from the boundary which makes it testable.
This pattern is useful when working with UI related code or database code. The main idea is to make the layer which changes frequently like UI code or database code as thin as possible. You will not have any unit test for this layer.
Move all the business logic to a different layer and have detailed unit testing for that.
The whole idea is to make the complex or frequently changing layer as HUMBLE or thin as possible and exclude writing unit testing for that (since it will not be worth the effort you are putting into it). Concentrate on the business logic layer by having detailed testing on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With