Join Simon Allardice for an in-depth discussion in this video Introducing mock objects, part of Foundations of Programming: Test-Driven Development.
- [Voiceover] Our entire aim in unit testing is to be able…to test pieces of code in isolation.…We're not writing tests that attempt to use…the full application but rather to end up with hundreds,…even thousands, of separate unit tests,…each one testing a single, small part of the system…independently of the others.…Now when the class, the component,…whatever you'd like to call the thing that you're looking at…the current unit under test, when that contains…totally self-contained behavior,…it's quite straightforward to test.…You can create new tests directly for this class…and its methods without caring about…what any of the other classes do…or even if any other classes exist at all.…
But let's face it, you don't have classes that exist…purely in a vacuum.…As soon as you've gone beyond the trivial,…these will need to interact.…They will interact with objects of other class types.…They'll interact with databases,…with websites and web services,…with the file system, and some of the things…they'll need to interact with are difficult.…
The course explores the jargon of TDD—test suites, test harness, mock and stub objects, and more—and covers how TDD is used in the most common programming languages and environments. Plus learn to create, run, and manage the tests and move to a test-first mindset.
- What is test-driven development?
- Using unit testing frameworks
- Creating tests
- Using assertions
- Creating multiple test methods
- Naming unit tests and test methods
- Testing return values
- Setting up and tearing down
- Introducing mock objects
- Measuring code coverage