 Hi everyone, so I am here tonight because I have a problem, my problem is I get nerdy about things and by things I mean everything and I spend way too many hours on Wikipedia accumulating knowledge about obscure topics like perhaps how big is a capybara and to justify this I do this thing where I try to make analogies to the things I learned to my work and I want to share with you tonight one of the one of the analogies that I made that helped me overcome the inertia to start writing tests and hopefully this can help some you as well so I make some assumptions about this working I make some assumptions about the audience for this talk one of which is that you actually want to write tests if you're not writing tests and you don't want to write them then there's nothing there that can help you if you're already writing tests this talk might not be for you but I included some animated gifts so stay focused the second assumption is that there's a basic understanding of why writing tests is a good idea so if you set through the previous talk and you felt like I should be doing this and that's a good start so you want to write tests and you know why but for some reason you're still not doing it and you seemingly it seemingly don't know why if you want to write tests and your hindrance is something like your boss doesn't let you write tests or your personal belief system prohibits you from writing tests then this is not a talk for you either I also have to warn you there's no code in this this talk it's more it addresses more the mental hurdle of starting to write tests so I got the idea of giving this talk a week ago at our retreat when I was talking to one of my colleagues we're getting quite philosophical talking about testing and we became a bit elitist and even Oster said the question can can you judge a person's character from looking at their tests and this kind of reminded me how how this analogy got me started so the assumption of this or the realization I had is that writing tests is like working out and if you're not on leaves now then bear with me because you can also say that exercising your code is like exercising your body and in particular writing test is like working out in the sense that we all know we should be doing it but when we're given the choice between going to the gym or grinding out level 241 of candy crush saga not give us and up like this and this disconnect between what we think we should be doing and what we're actually doing cost a lot of discomfort and it's make us make us worry and my hope with this talk is that I can relieve you of some of that worry and be happier so to back off I mean it's and just make sure if anyone is thinking this then yes you should be worried now but let's take this moment and see the benefits of writing tests because we understand that we should do it and we understand why so how does this relate to the benefits of working out the first one is quite obvious working out gives you confidence so think about demoing your code to the product owner as taking your shirt off in the bedroom only don't confuse the two second writing tests adds robustness to your code when we get older we run into the risk of suffering from catastrophic injury like shattered hip because as we get older our our bodies get weaker and this is also true for your code the older it gets the more prone it is to that catastrophic breakdown and lastly working out boosts your immune system and we don't want to catch bugs my girlfriend is here tonight and she hates pants so if we know that we should test and testing is awesome because it really is and why is it so hard to get started I think this is a purely psychological hurdle I mean there's nothing mechanical from stopping your fingers writing the tests on the keyboard and I identified four problems I had when I wanted to start writing tests and I drew on the sort of fitness community to help me solve this problem because it turns out that's getting off the couch and going to the gym is a well explored problem so the first reason it was hard is because of fear and this was by far the biggest reason and it's a it's a deep and primal fear appear of social exclusion because this is something we think we should be doing and if you've ever been to school which I hope most of you have been you might you might have found yourself in the position where the teacher is talking about something in the lecture and you don't really know what's going on but no one else is saying anything so I assume that everyone else already noticed it this and you were the only one not getting it I think there are more people there out there not writing tests than we think and if they're not then I was the only yeah so for me it got to the level where I became paranoid and I was watching my colleagues and I bet he's writing a test right now so how they deal with this in the fitness community is they recruit people to support you recruit people who share your goal they say that to get stronger you need to put yourself in an environment of strong people if you do pair programming spend the time on writing tests if you have a mentor tell them about your fear and them help you get started and if I think you will see that most of this fear was unfounded and if you genuinely think that you still have something to fear then you should come work for us instead after you recruit these people make yourself accountable to them so it can be something as simple as taking a primitive measurement like test coverage and setting a baseline for the product the second problem I faced when I wanted to start writing tests was becoming overwhelmed so this can happen for two reasons either you don't have enough information or you have too much information the first time I tried to write tests I had an environment something like this I had our spec in there I had factory girl at capybara the problem is I didn't know any of them or spec in factory girl quite radical these else I still get a headache sometimes when I when I work with it and I felt a bit like this so the way the fitness world suggests you deal with this is quite obvious start simple and for me that translated into using something like mini tests I even even cut rails out of the equation I just use mini tests my first test I tested the built-in classes in movie so focus on the things you know focus on the things you can do right now and focus on the things that are important the third problem I had with starting twice right test was overreaching in fitness this is called a flat-fire syndrome and every new year we see thousands of people starting their new lives they run 10 miles per day for two weeks living up seven almonds and after that they start feeling something like this and inevitably one miss in the diet we then lead them to think that everything is lost and they will go on a two-day binge the solution to this is to start life and strive for constant progress what you're doing when you're starting to write tests is to build a habit and you have to trust in accumulation and realize that a code base that took many weeks to put in a very horrid state is it gonna be fixed overnight so you might need to give up on your hopes on fixing that really annoying method right away and give it some time the fourth problem I encountered was that it all seemed like a paradox to me I was caught in some kind of catch 22 or chicken and the egg problem where to start writing tests I needed to know how to start how to write tests and write tests I need to start writing them and everything just seemed hard it turns out this wasn't a problem at all it's not a paradox you don't need to know how to write tests to start writing them and in hindsight the notion is quite absurd because if that were true then we couldn't ever learn to walk or talk or do anything so instead I focused on three things this is also copied from the fitness world do one thing at a time if you want to learn our spec capybara and factory go start with one of them and then you can add in the other two start with the most important thing first it makes a lot of sense to learn our spec before you learn should a matches and third but not least start now and I think this is the biggest takeaway if you're not writing tests what you want to literally start now if you bring brought a laptop fire it up in the break and write write a test so at the beginning of this talk I said that writing test is like working out and I hope I made a case for myself already but in case you're not convinced I I found some fitness quotes on the internet and I retrofitted them to apply to testing and here we go firstly when in doubt tests let the coverage be your stress reliever and lost but maybe most importantly test like Shining Tatum is watching thank you since I started writing tests I kind of traded one for the other yes I totally agree and I also contend that probably you shouldn't write tests for bad code like you can you can totally test it but it's still gonna be bad so when you're when you're trying to learn testing did you just as an thought experiment did you try like taking existing tests that other people had written and like experimenting with those to try and learn kind of what was going on or I think actually I think that was one of the things that contributed to my fear because I watched these awesome tests that my colleagues wrote and I only saw the result I didn't see the only effort today that went into learning all those things and then I felt a bit inadequate because this was nowhere near the level of test writing I think just from a personal experience I think one of the difficulties I had when learning testing was that it's the flexibility of Ruby and the ability to monkey patch and all these things building up and talking to each other Ruby got rails on top of Ruby and our step to probe it and then capybara to drive everything else so it wasn't very clear to me in the code which bit was which and that was part of my problem but the moment I started recognizing that this is our step and that's another bit it got a lot easier this is definitely one of the problems I had I was going to say one of the things that I found in my own experience and the teams that I've worked with and we've got an unknown and arguably unknowable number of independently moving parts in any significant application never without a test so you if you read people like James Brooklyn he's been arguing for a couple of years that it's impossible to fully test an application because there are so many logic paths through eating on trivial piece of code that you will miss something significant and that something significant will at some point come back and bite you in the short years and testing is one of the things that is delaying our new London school explosion but it is by no means and if you don't know what the new London school explosion was