Join Simon Allardice for an in-depth discussion in this video Creating multiple test methods, part of Foundations of Programming: Test-Driven Development.
- [Voiceover] I'm looking at the unit test code…and right now, my test is this one method just called test,…which is testing two methods in my BankAccount class,…the deposit method and the withdraw method…within a search for each one.…And while this is a simple and easy enough test to read,…it is more common to create separate methods…in the unit test code, testing these separate methods…in the application code.…So I'm going to split this up into one test for deposit…and a different test for withdraw,…because we really want our test to be small,…self-contained, simple, easy to read, easy to change.…
And if I get into the habit of mixing multiple tests…together from multiple methods in my application code,…then soon, they really won't be.…Now for purposes of time, I'm just going to copy…this entire method signature and duplicate it.…Using JUnit and Java, we have this @Test annotation…which is what's telling JUnit this is a test,…go ahead and run this method.…I still can't have two methods with exactly the same name.…
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