Macedonian Visual C# user group https://www.facebook.com/mkvcsughttp://mkdot.net/community/mknetug/mk_vcs/default.aspx Fake Mocking Dummy Wekoslav Stefanovski firstname.lastname@example.org email@example.com
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?
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
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.”
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”
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”
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
How to unit test in .net• NUnit• MSTest• TestDriven• Moq• RhinoMocks• Typemock• Microsoft Fakes• …