No video

The BEST Design Pattern for Maintainable Tests

  Рет қаралды 1,988

Gui Ferreira

Gui Ferreira

Күн бұрын

Пікірлер: 21
@antonmartyniuk
@antonmartyniuk 4 ай бұрын
I really like using this approach in my own tests, actually
@gui.ferreira
@gui.ferreira 4 ай бұрын
💪
@Laggie74
@Laggie74 9 ай бұрын
I can see that the Directors might be needed in more complex situations. But instead of creating multiple Directors for each pizza type, wouldn't it be simpler to just add a fluent method "StartWith(PizzaBuilder.PizzaType.Plain)" that takes in a class specific enum? I know this would place the responsibility of the default configuration as part of the Builder, but it would make sense here to simplify code maintenance and readability. You can still create the directors later if you want that control somewhere else. Thanks for all the great content.
@gui.ferreira
@gui.ferreira 9 ай бұрын
Thanks! That simple approach will often work just fine. The problem might be once you have multiple recipes where you keep their description. Directors let you segregate that. Thanks for the comment
@lunat38
@lunat38 Жыл бұрын
That is an ideal use case for Builders, well done! And thanks for sharing.
@gui.ferreira
@gui.ferreira Жыл бұрын
You bet! Thanks 🙏
@BenvdStouwe
@BenvdStouwe Жыл бұрын
After years of using the Builder Design Pattern to setup testdata I have found a better solutoin: C# records. I create a static method that instantiates a "default" instance of a record and with the "with" operator I setup further properties. This way I don't have to create Builder classes with all their properties and methods while I maintain the same functionality.
@gui.ferreira
@gui.ferreira Жыл бұрын
That's a good idea. I think it doesn't cover all the scenarios where I use Builders, however, I can see myself adopting it. Thanks for sharing!
@emiraksoy1520
@emiraksoy1520 2 ай бұрын
Awesome ! Definitely I will try this on unit tests , can we apply this integration tests ?
@gui.ferreira
@gui.ferreira 2 ай бұрын
Yes, you can. If you have repetitive data setup, the builder pattern can be magic.
@fandermill
@fandermill Жыл бұрын
Thank you for this great content, Gui! Do you think it is ok to set private fields with Reflection in the Build method to get the object in the needed state for the test? Or do you prefer an internal constructor/factory method that can be called trough the InternalsVisibleTo option? Or is there any other option?
@gui.ferreira
@gui.ferreira Жыл бұрын
You can do it. However, I avoid using techniques like reflection on my tests. On my tests, I avoid going around the public API. I want to feel the pain of consumers. So, if I feel the need to go around the public interface, I question my design first.
@bmassioui
@bmassioui Жыл бұрын
I prefer to go with factory method with private constructor ...
@gui.ferreira
@gui.ferreira Жыл бұрын
Builders are extremely useful when you have types involved in multiple Test Classes.
@stefan-d.grigorescu
@stefan-d.grigorescu 11 ай бұрын
​@@gui.ferreiraBut what is the difference between the Director and a Factory? In the end, both of them abstract the construction of an object, returning a specific default configuration (that could be further configured, depending on the type being created, if it exposes setters or not)
@gui.ferreira
@gui.ferreira 10 ай бұрын
​@@stefan-d.grigorescu the Director is also a creational pattern, but it's deeply connected to the Builder Pattern. You will use those two instead of a Factory when you have a complex initialization.
@stefan-d.grigorescu
@stefan-d.grigorescu 10 ай бұрын
@@gui.ferreira got it, thank you
@WhisperII
@WhisperII 2 ай бұрын
pizza without cheese is not a pizza))
@gui.ferreira
@gui.ferreira Ай бұрын
we are living in a crazy world 🧀 ❤️
Are You Covering All Scenarios With Your Tests?
8:31
Gui Ferreira
Рет қаралды 705
Building Complex Objects in a Simple Way with C#
12:19
Gui Ferreira
Рет қаралды 8 М.
ISSEI & yellow girl 💛
00:33
ISSEI / いっせい
Рет қаралды 24 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 32 МЛН
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 1,8 МЛН
managed to catch #tiktok
00:16
Анастасия Тарасова
Рет қаралды 46 МЛН
Think About this Before Creating a New Mock
13:12
Gui Ferreira
Рет қаралды 2,9 М.
Getting Started with Test-Driven Development
30:01
Gui Ferreira
Рет қаралды 1,9 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,6 МЛН
How do I Stay Organized as a Developer
15:21
Gui Ferreira
Рет қаралды 2,2 М.
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 149 М.
Modern Python logging
21:32
mCoding
Рет қаралды 179 М.
18 VS Code Tips to Code FASTER
17:39
Gui Ferreira
Рет қаралды 2,1 М.
ISSEI & yellow girl 💛
00:33
ISSEI / いっせい
Рет қаралды 24 МЛН