Development and why use it • The different types of tests • Writing our first tests • Refactoring • Test Doubles (Mocks, Stubs, Fakes, Spies, Dummies) • Test Quality
few parts of application together Uses mocked external dependencies Test a single function Use mocking for dependencies Only a few / possible only one test Run through the core journey Make use of actual external dependencies
from start to finish • Uses all really services ◦ Database ◦ Email ◦ … • Only made up of one or two tests ◦ Core user journeys • May interact with many different parts of you app in a single test ◦ Customer applications ◦ Admin applications • May require some seeding of external services • Could be behavioural tests
Mocks any dependencies of the class and function (Isolated) • Unit test should be able to run over and over in any order without the result changing (Repeatable & predictable)
2. Run tests (Latest test should fail || error) 3. Write code (Just enough code for the failing test to pass or error to go away) 4. Run test a. Test passed -> Continue b. Test Fails || New Error -> return to 3 5. Refactor (if required) REPEAT
Allowing for isolation of unit and integration tests • Do not necessarily require a mocking framework • Interfaces start becoming very important • Lots of different types of test double
to the logic within the code you are testing. PHP: Humbug (https://github.com/humbug/humbug) Java: PIT (http://pitest.org/) Go: Mutesting (https://github.com/zimmski/go-mutesting)
Manager I want my customers to be able to give simple feedback on their shopping experience So that I can gage how changes I make to the store affect customer satisfaction Scenario: When a customer gives a positive feedback Then the customer should be thanked for their feedback And the positive feedback count should have increased by 1 Scenario: When a customer gives a negative feedback Then the customer should be thanked for their feedback And the negative feedback count should have increased by 1 Scenario: When a customer gives a neutral feedback Then the customer should be thanked for their feedback
(@jamesbender) ◦ http://www.telerik.com/blogs/30-days-tdd-day-one-what-is-tdd • Code Coverage: Testing Private Functions (Me) ◦ http://mark-bradley.net/2017/03/11/code-coverage-testing-private-functions/ • SOLID Principles (Billie Thompson @PurpleBooth) ◦ https://purplebooth.co.uk/blog/2015/02/23/s-is-for-single-responsibility-principle/ • Speaker notes in these slides ◦ More in depth note about the slide ◦ Links to related articles