Mental hacks to master Unit Testing

• The vicious circle Agenda • Break the loop • Getting the time • Mental Hacks (Using the time wisely)

The vicious circle

What today is… …is Tomorrow No time to Crazy regressions unit test & unexpected bugs

What today is… …is Tomorrow Lack of No meaningful practice unit tests

Break the loop

Getting the time

Selling points ARGUMENTS to convert your boss a Unit Testing fan %

Argument to get time What is unit testing …in non techies words

Argument to get time: Pyramid of testing: UI - Service - Unit

Argument to get time The goal of unit testing is to sustain project growth by preventing software entropy

Argument to get time Solid unit tested code increases time to market by minimizing regressions

Argument to get time Writing unit tests today reduces the cost of the feature of tomorrow

Once you get the time… you need to be aware of…

Time stealers SNEAKY things that can fill your time

Time stealers Time running unit tests

Time stealers Time spent reading unit tests

Time stealers Time spent rewriting tests

Time stealers Time dealing with false alarms

Writing the cool test

Step back Set the concepts STRAIGHT

Concepts to get straight Test Accuracy …what meaningful or cool actually stand for

Concepts to get straight Functionality Test Result Correct Pass Fail ! # False Positive Resistance to Refactoring Broken ” False Negative ! Protection against regressions

Concepts to get straight Pillars of Unit Testing

Concepts to get straight Resistance to refactoring Focus Focus Maintainability Protection against regressions Choose Choose Fast Feedback

Mental hacks WRITING the test that helps

Mental hack: Black box testing Test WHAT happens, not HOW it happens

Mental hack: Anti Example

Mental hack: Example

Mental hack: Test what matters Focus on: important or complex code

Mental hack: Test what matters Shopping Cart in E-Commerce Validations in Form Heavy pages

Mental hack: Test what matters Complex / Important Complex or Important Over complicated Test Split No. of Dependencies or side effects Trivial Controllers Ignore Optional

Mental hacks The STRUCTURE of the test that helps

Mental Hack: Test Anatomy Given — When — Then

Mental Hack: Your test shall tell 2 Function — Scenario — Expected behavior

Mental Hack: Anti Example

Mental Hack: Example

Mental Hack: Your test aint’ wrong… 3 …your code is!

4 Mental Hack: Read the docs Get familiarized with your testing framework API

• The vicious circle Recap • Break the loop • Getting the time • Mental Hacks (Using the time wisely)

Spoiler alerts • WANT: a more scalable and flexible codebase • PRICE: the beginner struggle, but keep going • NEW YOU: you’ll write more testable code from start

Thank You Where to find me… DanielaValero.com