Upgrade to Pro — share decks privately, control downloads, hide ads and more …

.NET Day 2025: .NET Core Testing: pushing the l...

.NET Day 2025: .NET Core Testing: pushing the limits

Avatar for dotnetday

dotnetday

August 29, 2025
Tweet

More Decks by dotnetday

Other Decks in Technology

Transcript

  1. What is a Unit Test ? Fowler: it's a situational

    thing - the team decides what makes sense to be a unit for the purposes of their understanding of the system and its testing.
  2. Properties of (good) tests • Fast • Isolated • Repeatable

    • Self-Verifying • Timely https://medium.com/pragmatic-programmers/unit-tests-are-first-fast-isolated-repeatable-self-verifying-and- timely-a83e8070698e
  3. Powerful assertions 👑 Wrap in your DtSL 👑 Social Tests

    Solitary Tests Master LifeCycle + Inject Dependencies Reuse tests Organize tests hierarchy with Stubs plus W.A.F.
  4. Test cohesion adapter 1 Unit Tests adapter 2 Port 2

    Stubs (Spies, Fakes, Mocks ☠)
  5. https://martinfowler.com/articles/microservice-testing/#testing-unit-diagram agree 👍 split domain core and use cases 👍

    Domain code must be pure, Services (or Use Cases) need to collaborate (as a glue) Core
  6. Pitfall of Mocks • It’s easy to make mock instances

    incorrect – no guarantee it’s consistent with a correct implementation, which can lead to brittle tests. • Hard to refactor • Mocks discourage good interface design by encouraging testing implementation details instead of contracts. • Tests should be “executable documentation.” • Because they can use more-magical features like macros and reflection, they are less portable. https://xebia.com/blog/pitfalls-mocking-tests-how-to-avoid/ https://maherz.medium.com/stop-using-mocking-libraries-the-mistake-every-developer-makes-79a5d5189281
  7. Mocks = Dependency mismatch • Never Mock what you don’t

    own • Hand-written stub code • Hard, even impossible to refactor when contract OR behaviour changes ! https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#tradeoffs https://ryanharter.com/blog/2020/06/replacing-mocks/