Show notes
Hey there friends. So today I'm going to talk about testing and the users
of your code and how you should think about like how what do I test? Sopretty common question. And the answer is basically you take a unit of codethat you want to have tested that could be a single function or it could bean entire application.It really just comes down to what you want to get confidence in. Most of us
are probably in the camp of like I just want my to be sure that my entireapplication works and that's great. And that'sTypically where where I'mthinking and in my own mindset sometimes though, it's hard to accomplishthe thing that you're trying to test from a whole application perspectiveand that's when you go to lower level forms of testing but that's not whatI'm going to talk about today.So once you've identified the unit of code that you want to have tested the
next thing you need to do is think about who the users of that code are. Soif we're talking about a react component, for example, then you're going tohave two users of your code.And in fact most of the time,You're going to have two users of your code,
unless you're doing full-on and to end testing with nothing mocked. And thetwo users are the end user who's going to be interacting with that code andthe developer user who's going to be making network requests to your APIhandler or maybe they're calling into your function or their rendering yourcomponent, whatever it is.So you have those two two users of your code. And so then as you're
thinking about what you know, what you should write.For your test you'regoing to say okay well so what is the what do mind users do What are theuse cases that this code supports and how do I make like what are of thoseuse cases what are the most important things that I ensured don't break?Because they're like for an application there are some parts of the
application that matter more than others. And so you're going to identifyall the use cases that you want to support and kind of sort them in yourmind or maybe even write it down. The order of priority for those things.So once you have decided what use cases you want to support you just go
one.By one to write a test for that particular use case. And the way thatyou write that is you could even write this in code comments or somethingbefore you write the test you just say how do if I were a user manuallytesting this whether you're the end user or the developer user probablyboth how would I interact with this component to make it do the thing thatI'm trying to support?How do I show that use case in my test? And then you write code to do that.
I hope that's helpful and I hope you have a splendid day. Good luck.Andwriting those tests get yourself a lot of confidence and we'll see youaround.
