Write code first, test if you have time. • Often times, you'll be too exhausted (mentally) at the end of coding process to write tests. Saturday, 20 April, 13
Just make it pass first. • By focusing on writing only the code necessary to pass tests, designs can be cleaner and clearer than is often achieved by other methods. • Too many asserts might be a sign that your function is doing too many things - break it into smaller chunks. Saturday, 20 April, 13
breaks, it's isolated and easily traceable. • Testable units speed up development - Update the test case, make the code change, run the tests. • Confidence in making larger change sets. Saturday, 20 April, 13
affected by the latest code change. • Coverage reports help you discover potential weak spots / blind spots in your code. • Tests with examples will help in simulating actual use cases in an automated manner. • Tests becomes the documentation. Saturday, 20 April, 13
enjoyable (Gamification). • TDD gives you higher confidence that your code is doing what it's suppose to. • Working code every step of the way! Saturday, 20 April, 13
make the automated test part of your release process. • Continuous Integration - Automates repetitive and tedious task of testing and integrating your software. • Continuous Deployment. Saturday, 20 April, 13
bug? Write the test case to simulate it - failing test. • Write the bug fix. • Run test to ensure that bug is not repeatable or the exception is handled properly. Saturday, 20 April, 13
have a tendency to take shortcuts by writing conservative test cases. • One way to prevent this is to pair-program with another developer or a product owner when preparing the test cases. • Spec documents that includes examples can be useful to validate code behavior. Saturday, 20 April, 13
• Installing & setting up testing framework. • Read: Downtime of at least 1-2 days. • Nothing is full-proof! • It's easy to get lured into a false sense of security. • Even if u have 100% coverage, it still doesn't prevent unintended usage from breaking the code. • Bugs are test cases you have not written yet. Saturday, 20 April, 13
PHP projects. It provides both a framework that makes the writing of tests easy as well as the functionality to easily run the tests and analyse their results. • http://phpunit.de • Created by Sebastian Bergmann Saturday, 20 April, 13
but testing the codes as a user would use your app (ie. how diff parts of your code work together). • Process is the same, just that the tests are story-based. • User stories = Specs with examples Saturday, 20 April, 13
Sometimes codes being tested needs to interact with code that hasn't been written yet. • Libraries created for a specific purpose. • Eg. Written by a different team, scheduled for next iteration, just occurred to you that it's best done as a separate class. Saturday, 20 April, 13
cost involved. • eg. Time cost (network latency from DB queries or external server calls), triggers SMS, rate limited API calls. • Mock classes to simulate these objects, respond accordingly, contain the required attributes. • Only objects can be mocked, not static methods. Saturday, 20 April, 13