Join Simon Allardice for an in-depth discussion in this video Testing return values, part of Foundations of Programming: Test-Driven Development.
- [Voiceover] My current basic implementation…of the withdraw and deposit methods…in the bank account class don't return values,…they're both void.…But those methods do have an effect…on the state of the bank account object I can then measure.…So my test is to create that new object…to call one of those methods…and then what I assert, what I test,…is the assumed side effect.…Now, a quick sidebar here.…You'll slowly recognize that tests start…to take the same general approach.…We create an object or two, we do something to that object,…we test the result.…
And just as we can use the phrase red, green, refactor…to describe the overall process of test-driven development,…each individual test can typically be summarized…using three words beginning with "a,"…the three "a" rule: to arrange, to act, and to assert.…So to arrange is to get something set up to manipulate,…in this case we want to create our bank account object.…Then we act: we change it, we do something to it.…And then we assert: we check the result, we check it worked.…
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