Search⌘ K
AI Features

Grows Hard to Test

Explore the challenges in layered architecture when layers are skipped, leading to domain logic spread and increased test complexity. Understand how this impacts maintainability and testing effort, helping you appreciate the importance of strict layer separation for cleaner, more testable web applications.

We'll cover the following...

A common evolution within a layered architecture is that layers are being skipped. We access the persistence layer directly from the web layer since we’re only manipulating a single field of an entity, and for that, we need not bother the domain layer, right?

Skipping layers

Again, this feels alright the first couple of times, but it has two drawbacks if it happens often (and once someone has done the first step, it will happen often).

  1. We’re implementing domain logic in the web layer even if it’s only manipulating a single field. What if the use case expands in the future? We’re most likely going to add more domain logic to the web layer, mixing responsibilities and spreading essential domain logic all over the application.
  1. In the tests of our web layer, we not only have to mock away the domain layer, but also the persistence layer. This adds complexity to the unit test. And a complex test setup is the first step towards no tests at all because we don’t have time for them.

As the web component grows over time, it may accumulate a lot of dependencies to different persistence components, adding to the test’s complexity. At some point, it takes more time for us to understand and mock away the dependencies than to actually write test code.