Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Fake Mocking Dummy - Unit Testing in .net
1. Macedonian Visual C# user group
https://www.facebook.com/mkvcsug
http://mkdot.net/community/mknetug/mk_vcs/default.aspx
Fake
Mocking
Dummy
Wekoslav Stefanovski
swekster@gmail.com
sweko@mtdot.net
2. Why test software
• Bugs are bad, m’kay?
• Provides demonstrative proof that business
requirements have been met
• Reduces risk of failures (or incidents) once systems are
transferred to live operation
• Assures that the users for which the solution was
designed are able to operate productively.
– Performant
– Reliable
– Secure (and safe)
• When to stop testing?
3. Why unit test software
• White – box testing
• Created by people with best knowledge of the
system
• Unit testing promotes flexible design
• Better complexity management
• Automating tests lead to fearless coding
• Free regression coverage
4. Unit testing myths
• “Testers test, developers develop”
• “Its dull to write tests.”
• “There’s no time to write tests.”
• “We’ll write the unit tests later.”
• “The code will change, so the tests will fail in
the (near) future.”
• “The test we wrote some time ago (probably)
don’t work anymore.”
5. Unit testing myths
• “Unit testing is weak at finding problems
that haven’t been considered.”
• “It takes too much time and effort to think of
all possible cases and write all those tests.”
• “Methods not being easily testable”
• “Not feasible for big projects”
• “Not feasible for existing projects”
6. Unit testing myths
• “It saves money”
• “It reduces the number of bugs”
• “It brings a higher code quality”
• “It improves performance”
• “It’s easy to unit-test concurrency”
7. Fakes and Stubs and Mocks, oh my
• Dummy
Just a placeholder object, unused and unusable
• Stub
A placeholder implementation, returning defaults
• Fake
A working, albeit trivial implementation
• Mock
A simulated object that mimics behavior
8. How to unit test in .net
• NUnit
• MSTest
• TestDriven
• Moq
• RhinoMocks
• Typemock
• Microsoft Fakes
• …