Test-driven development is a pattern of writing code in a systemic way, where you first write a test before writing the method for the test. Explore and use that pattern in this video to writing out new code for your application.
- [Instructor] So we now at least have…a rough understanding of how unit testing works.…For the remainder of this course,…we'll use TDD to approach the rest of our lessons.…First step, as always, is a failing test.…So let's add a new test method,…to test calculating the tax for a receipt.…We'll open up our receipt test file,…which is located at test, ReceiptTest.php…After this, we need to add a new method.…In this case, test tax.…
So after line 24, we'll add a few blank lines,…and add public function testTax.…And now we can follow the pattern from earlier.…We can add an input amount variable of equal to 10 dollars,…or 10.00, on line 27.…After this, we need a tax percentage input…of 10%.…So on line 28, we'll add taxInput…and it'll be equal to 0.10…After this, we can call a tax method on our receipt object.…
Passing in both the amount and the tax,…and then returning an output.…So we'll have output is equal to…this arrow Receipt arrow tax,…and we'll accept the inputAmount first,…and then the taxInput.…Finally, on line 30,…
- Why use unit testing?
- Writing unit tests
- Extending unit tests
- Filtering PHPUnit tests
- Building dummy objects
- Working with data providers
- Writing an exception-based test
- Using TDD tactics
- Using PHPUnit advanced tactics, such as database tests
Skill Level Intermediate
Managing PHP Persistent Sessionswith David Powers2h 41m Intermediate
1. The Basics of Test-Driven Development
2. Advanced Test-Driven Development
3. Test-Driven Development Tactics
4. PHPUnit Advanced Tactics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.