You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{Describe the context and problem statement, e.g., in free form using two to three sentences. You may want to articulate the problem in form of a question.}
12
+
13
+
## Decision Drivers <!-- optional -->
14
+
15
+
* {driver 1, e.g., a force, facing concern, …}
16
+
* {driver 2, e.g., a force, facing concern, …}
17
+
* … <!-- numbers of drivers can vary -->
18
+
19
+
## Considered Options
20
+
21
+
* {option 1}
22
+
* {option 2}
23
+
* {option 3}
24
+
* … <!-- numbers of options can vary -->
25
+
26
+
## Decision Outcome
27
+
28
+
Chosen option: "{option 1}", because {justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force {force} | … | comes out best (see below)}.
When unit testing a service, the standard unit is usually the service class, simple as that. The test will mock out the layer underneath in this case the DAO/DAL layer and verify the interactions on it. Exact same thing for the DAO layer mocking out the interactions with the database (HibernateTemplate in this example) and verifying the interactions with that.
78
+
79
+
This is a valid approach, but it leads to brittle tests adding or removing a layer almost always means rewriting the tests entirely. This happens because the tests rely on the exact structure of the layers, and a change to that means a change to the tests.
80
+
To avoid this kind of inflexibility, we can grow the scope of the unit test by changing the definition of the unit we can look at a persistent operation as a unit, from the Service Layer through the DAO and all the way day to the raw persistence whatever that is. Now, the unit test will consume the API of the Service Layer and will have the raw persistence mocked out in this case, the HibernateTemplate:
0 commit comments