DEV Community

Discussion on: My DDD journey

Collapse
 
rafalpienkowski profile image
Rafal Pienkowski

I think that my testing strategy changed a little bit. I appreciate the TDD approach during the domain modelling process. Why do I believe TDD is so handy there?

Let's imagine that we made an Event Storming session. We found our core domain. We have Event Storming session artefacts like domain events, commands, policies etc. Now it's time to create the first model. We can sketch the first class with behaviours discovered during previous talks with the domain experts. Here the power of TDD comes. We have source code of the core domain which shouldn't have dependencies to other modules. That makes it easy to write unit tests. We can write some test and check our assumptions and validate if the created domain model is correct. Here is an excellent place for TDD. You should find invariants and policies against which you can write tests before you code the logic. Theoretically, even domain experts could be able to understand experiments and give us some feedback. Unfortunately, I haven't met such an expert yet.

You said that you're trying to use TDD to build a web app with DDD principles. In my projects, the Web App is only a user interface. According to the Onion Architecture this is the outermost layer, so I try to avoid DDD there. I'm using the Web App only to produce CQRS' commands and queries or when I don't have CQRS into play, to invoke application services. When it comes to testing a web app, I limit myself only to write some integration tests which covers the sunny day scenarios.

I hope I answer your question.

Collapse
 
freddyhm profile image
Freddy Hidalgo-Monchez

Yes that's actually very insightful so thank you for taking the time to reply! I started writing the core domain in a web app first (simply out of familiarity) and then I was thinking of extracting it away into its own API project to somewhat achieve what you mentioned. I can see how the web app can simply be a UI that produces CQRS commands and queries and I like that approach. Do you know of a sample github repo that demonstrates this with DDD or tutorial?

Thread Thread
 
rafalpienkowski profile image
Rafal Pienkowski

I think you can take a closer look to Kamil Grzybek's blog and posts about the modular monolith. He had also created a quite advanced project on the Github. The code is written in C# but even if you are not familiar with it you could be able to catch the idea which stands behind it. I hope this will be helpful.

Thread Thread
 
freddyhm profile image
Freddy Hidalgo-Monchez

Great, I'll be sure to check that out. Thanks for your help Rafal!