'philip schwarz' via Growing Object-Oriented Software
2016-08-06 20:50:55 UTC
Just bumped into
this: http://enterprisecraftsmanship.com/2016/07/05/growing-object-oriented-software-guided-by-tests-without-mocks/
From the first part of the post:
"So here Iâll take the most canonical example of using mocks I could find â
the one from the GOOS book â and will show how the use of mocks damages the
design. Iâll also show how much simpler the code base becomes when you get
rid of mocks and apply the guidelines I described in the previous posts of
this series."
"Despite all the great tips and techniques the book proposes, the amount of
potentially harmful advice is quite substantial as well.
The book is a strong proponent of the collaboration verification style
<http://enterprisecraftsmanship.com/2016/06/09/styles-of-unit-testing/> of
unit testing even when it comes to communication between individual objects
inside the domain model. In my opinion, itâs the main shortcoming of the
book. All other shortcomings flow from this one.
To justify this approach, the authors allude to the definition of
Object-Oriented Design given by Alan Kay:
*âThe big idea is âmessagingâ [âŠ] The key in making great and growable
systems is*
*much more to design how its modules communicate rather than what their
internal*
*properties and behaviors should be.â*
They then conclude that interactions between objects is what you should
focus on foremost in unit tests. By this logic, the communication pattern
between classes is what essentially comprises the system and identifies its
behavior.
There are two problems with this viewpoint. First, I wouldnât bring the
Alan Keyâs definition of OOD here. Itâs quite vague to build such a strong
argument upon and has little to do with how modern strongly-typed OOP
languages look like today.
Hereâs another famous quote of him:
*âI made up the term âobject-orientedâ, and I can tell you I didnât have
C++ in mindâ.*
And of course, you can safely substitute C++ with C# or Java here.
The second problem with this line of thinking is that separate classes are
too fine-grained to treat them as independent communication agents. The
communication pattern between them tend to change often and has little
correlation with the end result we should aim at verifying.
As I mentioned in the previous post
<http://enterprisecraftsmanship.com/2016/06/21/pragmatic-integration-testing/>,
the way classes inside the domain model talk to each other is an
implementation detail. The communication pattern only becomes part of API
when it crosses the boundary of the system: when your domain model starts
interacting with external services. Unfortunately, the book doesnât make
this distinction.
The drawbacks of the approach the book proposes become vivid when you
consider the sample project it goes through in the 3rd part. Not only
focusing on collaboration between classes entails fragile unit tests that
couple to the SUTâs implementation details, but it also leads to an
overcomplicated design with circular dependencies, header interfaces, and
an excessive number of layers of indirection."
Philip
this: http://enterprisecraftsmanship.com/2016/07/05/growing-object-oriented-software-guided-by-tests-without-mocks/
From the first part of the post:
"So here Iâll take the most canonical example of using mocks I could find â
the one from the GOOS book â and will show how the use of mocks damages the
design. Iâll also show how much simpler the code base becomes when you get
rid of mocks and apply the guidelines I described in the previous posts of
this series."
"Despite all the great tips and techniques the book proposes, the amount of
potentially harmful advice is quite substantial as well.
The book is a strong proponent of the collaboration verification style
<http://enterprisecraftsmanship.com/2016/06/09/styles-of-unit-testing/> of
unit testing even when it comes to communication between individual objects
inside the domain model. In my opinion, itâs the main shortcoming of the
book. All other shortcomings flow from this one.
To justify this approach, the authors allude to the definition of
Object-Oriented Design given by Alan Kay:
*âThe big idea is âmessagingâ [âŠ] The key in making great and growable
systems is*
*much more to design how its modules communicate rather than what their
internal*
*properties and behaviors should be.â*
They then conclude that interactions between objects is what you should
focus on foremost in unit tests. By this logic, the communication pattern
between classes is what essentially comprises the system and identifies its
behavior.
There are two problems with this viewpoint. First, I wouldnât bring the
Alan Keyâs definition of OOD here. Itâs quite vague to build such a strong
argument upon and has little to do with how modern strongly-typed OOP
languages look like today.
Hereâs another famous quote of him:
*âI made up the term âobject-orientedâ, and I can tell you I didnât have
C++ in mindâ.*
And of course, you can safely substitute C++ with C# or Java here.
The second problem with this line of thinking is that separate classes are
too fine-grained to treat them as independent communication agents. The
communication pattern between them tend to change often and has little
correlation with the end result we should aim at verifying.
As I mentioned in the previous post
<http://enterprisecraftsmanship.com/2016/06/21/pragmatic-integration-testing/>,
the way classes inside the domain model talk to each other is an
implementation detail. The communication pattern only becomes part of API
when it crosses the boundary of the system: when your domain model starts
interacting with external services. Unfortunately, the book doesnât make
this distinction.
The drawbacks of the approach the book proposes become vivid when you
consider the sample project it goes through in the 3rd part. Not only
focusing on collaboration between classes entails fragile unit tests that
couple to the SUTâs implementation details, but it also leads to an
overcomplicated design with circular dependencies, header interfaces, and
an excessive number of layers of indirection."
Philip
--
---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriented-software+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriented-software+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.