The Secret of Unit Testing I Learned by Failing @zoran-horvat
The Secret of Unit Testing I Learned by Failing  @zoran-horvat
Uploaded March 2024 | Updated November 2026, 3 days ago
Download source code ► patreon.com/zoranhorvat
Join Discord server with topics on C# ► codinghelmet.com/go/discord
Enroll course *Beginning Object-Oriented Programming with C#* ► codinghelmet.com/go/beginning-oop-with-csharp
Subscribe ► youtube.com/channel/UCxsWfh8LCcn55mFB6zGBT1g?sub_confirmation=1

Here is the riddle for you to solve: Suppose there is a method that creates and populates a collection. There are two possibilities before you:
(1) Assert that the collection has the exact expected content, or
(2) Only assert that its size is as expected.
Which of the two unit tests is better at testing that method?
I will argue that checking the size of the resulting collection is, by all means, sufficient. Whatever you add to the unit test will not improve your chances of isolating bugs. If you disagree, then I will kindly invite you to watch this video and learn about one of the most frequent fallacies in unit testing.
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️COPYRIGHT NOTICE:
The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.

#csharp #dotnet #unittesting
The Secret of Unit Testing I Learned by FailingStop Using Primitive Types in Your Minimal API EndpointsThe Ultimate .NET Collections Cheat SheetObject Validation and Invariants End at This PointThe Secret Ingredient to Choosing Between IEnumerable and Collections in C#Build a Lightweight Change Tracker for Dapper: Optimal SQL Without EF CoreWhat are ValueTasks Used For?Master the Design of Classes (Part 2)EF Core Mapping: Dark Magic (Here Is Why)Advent of Code 2024 Day 3 - Full SolutionFavor Declarative Design and Cure That Code ClutterFind the Bug in 5s
Zoran on C# |

The Secret of Unit Testing I Learned by Failing

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER