How to Code: Web Development

A podcast for aspiring web developers


7: The importance of testing


Robert: [00:00:00] Hey, everyone. Welcome back to another episode of the, how to code podcast. I'm your host Robert guts. And in this episode, I want to talk to you about the importance of testing and writing tests for your applications. So kick things off in this first section I wanted to discuss basically what testing is and why developers write tests in the first.

And so the primary reason why developers write tests is you can really summarize, you can summarize it with a single word and that word is confidence. Tests are intended to provide you with the confidence that you need to know that your application is working correctly. So at the end of the day, the whole reason why we write tests is to make sure that our application is behaving in doing the things that we expect it to do.[00:01:00]

And then when it doesn't do the things that we do, if we have tests for it, those tests are going to fail and then those tests will notify us and let us know that something's gone wrong, something's broken. And that we need to address an issue with within our, uh, within our applic. I think also the thing about testing is that virtually everyone knows that testing is important.

And I don't know, uh, too many people who would argue that testing is not important and you, that you shouldn't do it. We all know that it's important and that you need to do it. But unfortunately, a lot of people still don't know how to do it.

The interesting thing about testing is that it's one of those things that virtually every software developer understands and knows that testing is really important. But the ironic thing is that there's still a whole lot of developers who don't know how to do it. And it's a really strange and odd thing.

And it's something that I've learned. Um, [00:02:00] And seen, um, quite a bit firsthand, uh, working for a testing company. If, if you haven't listened to prior episodes, uh, I currently work for a Cypress, which is an end to end, uh, testing tool. And so I eat, breathe, drink, sleep testing stuff, day in and day out. And, um, It's just funny to me and really strange that, you know, virtually every developer understands and knows that testing is really important, but there's still so many developers out there who don't know how to do it, and they don't know how to do it.

Well, that's for sure. And, um, I kind of wanted to talk about some of those issues in this episode and give you some pointers and some advice on how to get started with testing and how you can use testing to kind of set yourself apart from everyone else when you're applying for your jobs. And so we'll get into that in a little bit.

Um, but I think the important thing to talk about right off the bat, now that we understand a little bit about why you write tests it's so that you can have [00:03:00] confidence that your application is working correctly. It's just understanding that testing is really hard, um, to write good tests and to test well, it's very difficult and it's no different than writing than writing.

Software is difficult. So writing software is incredibly hard to do it well is very difficult. And writing tests for your software is also very hard and very difficult because tests are also code and writing code is hard. Programming's difficult. And so not only is writing your application difficult, but writing tests for your application is also difficult.

And I think one of the things that makes it so difficult is that there really isn't one single right way to do it, which is also what makes writing software very hard. There isn't one stack there isn't one way to go about writing software. Um, you can do it basically an infinite number of ways. And the same is true with [00:04:00] testing, which is why.

A lot of information on testing or people's understanding of testing can be really, um, ambiguous and people don't really understand it fully because there's just, it's kind of like the wild west out there, frankly. Um, there's so many different types of tests and developers. If you're not aware, I've talked about this before, have very strong opinions and they can be very dogmatic about how many tests should be written.

What tests need to be written, what tools and software you need to write tests and all these kinds of things. Um, but the, the funny thing is that someone. You know, who works for a testing company like myself. I work at Cyprus and I literally create educational content around testing for a living. I teach testing to people for a living.

Um, I can tell you firsthand that it is basically like the wild west out there when it comes to finding good information and content [00:05:00] about testing. And so. I'll get into that a little bit more later and talk about, you know, our solution to that. There's some curriculum and some content that we created to hope to try and help, uh, alleviate that and provide good content and good information about testing.

And I'll get into that in a little bit later in the episode. Um, but some of the, one of the things I wanna talk about that makes, um, testing difficult too, for software developers is that testing is fundamentally a, a mindset. And I think it's, this is one of those foundational issues that a lot of developers don't fully grasp or understand.

It's very, very different. You have to be in a very different mindset when you're writing tests, as opposed to writing code for features or fixing bugs and things like that. And you can fundamentally think this about in two, these two very basic ways, the breakdown kind of goes [00:06:00] something like this.

Developers create things and QA professionals try to break things. So I'll, I'll repeat that one more time. Developers create things, meaning they're writing code to add features, fix bugs and things like that. And then the QA professional is trying to break your feature and, you know, try and introduce that bug again against your code.

That's trying to fix it. So the two fundamentally different approaches and ways of thinking about, um, an application and about writing software. And this is the rub where a lot of developers struggle with writing good tests and becoming good testers is because they don't adopt this mindset. When they're writing tests, they start writing tests as a software developer, thinking of.

Adding features fixing bugs instead of thinking, okay, what are all the possible edge cases, edge cases and [00:07:00] situations in which this feature or this implementation could be broken, like take, for example, a form input or just a single input on a form. What if someone and, and just like an email, let's say you're trying to capture in this form.

Okay. What if someone enters in a bunch of random characters that are not a part of an email address, what should. What happens if they enter in a bunch of numbers? What if those numbers are either positive or negative or what if they try to enter in some JavaScript code into that input what's gonna happen?

So there's all these like weird. Kind of edge cases and weird things you have to think about. And one of the reasons why it's so important is because frankly, the Internet's a very scary and dangerous place and you cannot trust your users ever under any circumstances. That's really important.

Unfortunately, we live in a world where there are a bunch of malicious actors and there are legitimate hackers. I don't need to make you aware of this. We see this all the time. [00:08:00] With large companies having breaches and personal information and credit cards being stolen. There are a lot of people out there who make a lot of money by compromising applications and getting access to your users' private and personal information.

And it's up to you to do your best job, to make sure that those people never get access to that information. And testing is one of those ways. And so you kind of have to think like the bad guy does in order to do that. You have to think of every possible situation where someone could break in and do something nefarious and wicked in your application.

And so it's a completely different mindset shift. And then the next thing that, you know, people really struggle with and what makes testing so difficult is frankly, especially when you're first starting out, this is a question that comes up again and again, and again is what, what do I test. Right. Like you have this huge application, where do you even begin?

What are the most important things to [00:09:00] test? And if you don't know what to test, you can have all the fundamentals and the technology and all the tools and everything to write tests. But if you don't know what to test, then you don't have any place to get started. And so like a lot of questions that people have is, you know, what should I test?

What types of tests should I write? There's so many different kinds. How many tests should I write? And, or how useful are my tests? Are the tests that I'm writing any good. And then, you know, getting back to what type of test should I write, just to give you like a little sample of kind of different types of tests and testing strategies, you have unit testing, integration testing, end to end testing, component testing, regression, testing, smoke, testing, performance testing, and the list goes on and on and on and on and on, and people get really hung up.

On knowing, trying to figure out, okay, what should I test? How many tests should I write? Things like that. And the thing you have to keep in mind when you're [00:10:00] trying to become good at testing is again, one word confidence. So it always comes back to confidence. So to answer all of those questions, what should I test?

Basically, what you're trying to test is the most important pieces of your application, right? What are the pieces of your application that cannot by any means that can never fail? That can never be compromised. Right? So for example, if you have a login form that's critically important because users need to be able to log in and log out out of your application.

And you need to test that thing thoroughly because it's, it's incredibly important. It's probably one of the most important pieces of your application. Then if you're like eCommerce, for example, you need to test that people can, you know, add products to their shopping cart, that the shopping cart works, that they can enter in their billing information and shipping information and that their credit card information and all that sensitive information is handled in a way that.

Secure and private and won't be exposed to the [00:11:00] public and could potentially be compromised. So you're always looking for, to test like the mission critical pieces of your application first, and then you can spread out to more secondary and tertiary issues, but the critical stuff you have to have test for right off the bat.

And then once you have those tests, again, that should make you more confident that your application is working as expected. And then when you ask questions, like what types of tests should I write? How many tests should I write? All those kinds of things. Again, it comes back to confidence. So if the tests that you you're writing are giving you the confidence that things are working as expected, then you're good.

It doesn't really matter if you write five tests or if you write 500. As long as whenever those tests run and they pass. If you feel like your application is working as expected, based upon the test that you have, then you have sufficient test coverage in my opinion. And so this next section, I wanted to give you some, [00:12:00] um, practical advice and tips on how you can actually go about learning, how to test and.

I'm obviously gonna give this from the perspective of assuming that you've, you know, little to, nothing about testing in the first place, cuz this podcast is really geared towards, uh, developers who are trying to get in break into tech and get their first tech job. And so they're either teaching themselves or they're going through a bootcamp or they're watching YouTube videos and TMY courses and things like that to try and learn how to code and get a.

So I'm giving this advice, assuming that you know, absolutely nothing about testing, what I was talking about previously, my intention was to kind of. Overwhelm you just a little bit. And I did that on purpose because I wanted to demonstrate just how complicated testing can be. And that's also one of the biggest problems with testing is that, like I said before, it's very difficult.

Like writing software is [00:13:00] software is complicated. Writing tests is also complicated because so software itself is complicated. Um, even though it is complicated, it doesn't always have to be. Um, these things can always be broken down and simplified, which is the job of any great engineer and developer.

That's what you do day in and day out. You take complex problems, you break them down and simplify them into simple steps that you can execute one after the other, until that complex piece is completed. And so here's some practical advice that I would give you on how to, um, get started with testing. So the first thing I would recommend you do, if you are brand new to testing, you've never written a test before in your life and you know nothing about any of this or how any of this works.

I would recommend you get started with end to end testing and end to end testing is a kind of testing that essentially tests every piece and part of your application. And what I mean by [00:14:00] that is essentially what an end to end test is. You basically write some code that then, um, gets executed. And so this is an automated test.

The computer is running your code and doing this test. And what will happen in the end to end test for example is, um, in the context of a web application, which is, uh, this is specifically geared towards, uh, web applications. This is a web development podcast after all, um, your test runner is going to open up a browser.

And then it's gonna do a whole bunch of things that typically a user would do, but that you've written in code. So for example, you're gonna within your test, you're gonna say, okay, I want to visit the homepage. And then I wanna make sure that this button exists on the homepage. And then when I click on this button, I wanna make sure that my application then navigates to the correct URL.

Now you could very easily do this manually where you just manually [00:15:00] go in and click around. But the beauty of having this automated is that this thing will run every single time, significantly faster than you ever could manually. And it takes out of the equation, a lot of human error and the beauty about end to end testing, as opposed to other types of testing, like unit integration and things like that.

Is that it's much easier, I think for beginners to wrap their heads around it, because basically what you're doing is you would, you're basically writing in code all of the things that you would typically be doing by hand or manually. So when like virtually every developer test to some extent, but most of them test manually.

So like when you input it, when you're creating a form and you're writing the HTML and the CSS and the Java script, After you've completed it, or while you're in the process of building it, you're gonna be typing in the form, submitting the button and make sure that the form is doing the things that you expect it to do.

And [00:16:00] so then with an end to end test, all you're doing is writing some code that will repeat those exact same steps. That you're doing manually only at a much faster rate. And it'll do that every single time consistently without potential of human error. So like, while you could be making typos in the form and mistakes like that, as long as your code doesn't have any typos, the test runner and your test suite is gonna be running those tests exactly the same every single time over and over and over again, which is what makes them so powerful.

And it's much easier in my opinion, conceptually, to wrap your head around what an end to end test is without getting in the nitty gritty details of like unit testing and integration. And while I think those things are important, um, specifically end to end or unit testing and integration testing, starting off with end to end, I think is the easiest, like ways of dipping your toes into the testing water, if you will.

So start there. So. Then the next [00:17:00] question is, okay, well, how do I actually write end-to-end tests now? I'll be perfectly honest with you. I'm a little bit biased here because I work for Cypress, but Cyprus, in my opinion is the best end-to-end testing tool that exists right now. Um, Cyrus does not sponsor this show.

Um, they do pay me a full-time salary, obviously, but I'm not promoting them or talking about them on my own personal podcast, which I do out of my own time. I don't make money doing this. Um, because of some incentive by my company, I came to work for Cypress because I thought I was you already using it to begin with.

It made a huge difference in my productivity and my confidence in my applications. And I just thought it was an amazing tool. So I sought them out specifically and started to work for them just because I'm a huge fan and a big believer in what they do. So. Um, start with Cypress. There is another tool out there called playwright by Microsoft, and you're more.

And I think you should probably also check that at two and see which [00:18:00] one you prefer. But Cyprus, I think, especially for beginners and it's not just for beginners, it's it's for people who are super advanced as well. Cyprus because of the way that it works and how visual it is. And because of the, the developer experience of it is so solid, it's gonna help you understand what is actually happening inside your test, because you can click on things on the left hand side, see all the steps that are being executed, and you can go back in time and it's called time travel debugging, and see back in time, all the steps that you.

Tests went through and it's, so it gives you so much insight and clarity about what's actually going on in every single step of your test, which something like playwright, in my opinion, uh, just does not do anywhere near as good of a job. So. Just start with Cypress. Trust me on this one, give it a, give it a go use that one and just get started using that.

Um, another thing too, that you can learn, and this is a [00:19:00] shameless plug on my part is that, uh, my coworker and I Kevin at the time created an entirely free curriculum to teach you everything you need to know about testing. At a website called or the, the address is learn.cypress.io. So L E a R N dot C Y P R E S s.io.

I will put a link in the show notes, um, for that. And basically what it is, it is a website and an application that contains four courses that will teach you everything you need to know from writing your very first Cypress test, all the way to like very advanced, Cy, um, testing techniques. And not only do we teach you how to use Cyprus itself.

We teach you all the fundamentals and things that you need to know about the mindset, what automated testing is versus manual testing and all these other things that are not necessarily specific to Cyprus itself, but are very, very important when you're learning the [00:20:00] testing. And. We give it all away for free the whole, all the curriculum, all the content, the application itself is completely open source.

You don't have to sign up. You don't have to give us an email address, nothing. You just go to that site and you just start learning immediately. And I just released, um, fairly recently, um, a new, I updated the first course, and I have videos for that entire course. So you can read everything there's quizzes at the bottom.

Of every lesson to make sure you're learning things and that you can check your learning. And then there's also videos for every lesson in the first course. Um, I think another super useful thing and probably the, one of the best ways for you to learn how to really get good at testing and learn how to write good tests is to read other people's code, like read other people's tests.

So. By looking at, um, various open source projects that you're a fan of and a lot of open source projects. Thank God do have, excuse me, I do [00:21:00] have a lot of tests for them. And so that hands down the best way I think for you to get good at testing is to read other people's tests because it's gonna teach you not only.

How to think about what to test, cuz you'll see exactly what they're testing and why they're testing it, but you'll also see how exactly they do go about testing that feature or that thing. And tests really serve as a sort of documentation. And oftentimes if. I'm introduced or I'm trying to learn a new application.

The, if it has tests, that is absolutely the best way for me to wrap my head around what the application does and how it works before I even start diving into the code. I'll immediately open up the test folder. And just start reading through all the specs, all the tests, because the tests will tell me exactly what are like the most important and key features and functionality of that application way faster and way better than me just reading through the source code [00:22:00] like ever could.

This is how I learned how to, Test and start writing tests is I just started reading, um, code and tests on various open source projects until I kind of could wrap my head around it. So those two things check out the curriculum at learned at Cypress studio and read and look at tests for open source projects.

Another thing that you can use, um, if you're not sure. Well, which open source projects should I learn or look at these tests for? We created a, , an open source application called the real world application. And basically what this is, is it is a Venmo clone. It is a full stack application that you can download and clone and play around with that basically allows, allows you to.

Send and transfer, send and transfer, uh, money between friends, the same way you would with Venmo. Um, it's not, it's meant to be completely for demonstration purposes, so it's not like a, it's not like actually in production and being used by real users. It's simply for teaching and instruction, [00:23:00] but that application not only teaches you how to build, you know, you can look at, see how to build a full stack application entirely in JavaScript and node, but then.

You can also read all of our tests and it shows you basically how we go about testing it. And it includes all of like the best practices and things that we recommend for testing. And then over on the learn dot Cypress site, we have full blown explanations for the, for some of the most important tests.

So we'll walk you through line by line of. I forget how many tests, I think like 40 different types of tests, specifically walking you through line by line, what this test is doing, why we decided to test it that way and everything. So those three resources are huge. So it's the learn web, the learned Cypress study site, reading other people's tests and open source projects and the real world app, which is something that we also created at Cyprus.

Okay. So in this next session, I wanted to give you some [00:24:00] practical advice and tips on how testing can help you get your first dev job. So if you take the time and go the extra mile, if you will, to learn how to test, in addition to learning, you know, your fundamental web technologies like HTML, CSS, JavaScript, and whatever your backend language is, if you're going that route, if you wanna go full stack or whatever, You are going to be way ahead of the curve in the competition because virtually no junior developer knows how to test, which is really sad.

And part of my reason for creating this content in this episode in the first place is I'm trying to change that. But like, if you think about it, and even in my experience, there's a lot of mid-level and even senior level developers who don't know how to write tests. So. One of the things that I did early on in my career, or not early on, but I would say in the middle of my career, [00:25:00] because I didn't know how to test early on in the beginning.

I learned kind of, um, as I had a couple of years under, uh, under my belt, but, uh, one of the tactics that I've used to help me get jobs and to impress companies when I'm interviewing for them is. Uh, anytime that a company gives you like a take home project, which is very common, you'll often have like a technical interview where you have to do some coding and stuff live or over like a zoom call or things like that.

Or they'll ask you a bunch of technical questions, but then a lot of companies will also give you like a take home project. Well, they'll ask you to build something or to create some, a feature or something like that because they wanna see your code and kind of see how you work and how you think. But the thing that I did once I learned how to test to kind of give myself an edge compared to everyone else applying for this job, is that not only did I complete the project, but I wrote tests for my code [00:26:00] for that project.

That gave me such an edge and like different. That was such a differentiator between me and everyone else because companies hardly ever ask you to do this. And they never, they virtually never expect. You to write tests for those take home projects. So if you go the extra mile and not only do a good job on completing the take home assignment in the project, but if you write tests for it,

they're gonna be blown away and it's just one of those tactics and techniques that will completely set you apart from everyone else. Applying. For the job because virtually no one does this and not only will having tests for that project demonstrate your knowledge and expertise of the thing that they ask you to do, but it also demonstrates to them that you really care a great deal about code quality and about the applications that you work [00:27:00] on.

And that you're a professional. Like if you know how to write tests and you can demonstrate that not only can you write the code to implement the feature and to do the thing, but you can also write tests for it. I'm telling you it is gonna absolutely blow companies away. And I seriously cannot over emphasize that enough.

I have reviewed in the last seven and a half years or so that I've been doing this as a full-time developer, countless resumes and portfolios of people trying to get their first jobs in tech and not a single one has anything related to testing on the resume. And none of their portfolio projects have tests, not one.

So if all the competition is so fierce out there, and it's so difficult to get your first job and to break into, into tech. But if you can write tests, For your portfolio projects and demonstrate that you [00:28:00] understand testing that is gonna set you so far above and beyond the rest of the competition.

It'll it. It's just one of those things that I don't hear people talking about, which is very surprising, and it's a game changer. It's an absolute game changer. Like some of the other pieces of advice I've tried to give on previous episodes, it's just another layer. Another one of those things that you can do that no one else is doing that just separates you from the rest of the competition.

Also, if you take the time to learn testing this early on in your career, and when you're just getting started, you're gonna have a leg up from everyone else because you literally need to learn how to write tests. Anyways, it's incredibly important. And so if you can show that you already know how to write tests.

And you're just getting started in your career. You're way ahead of the pack. You're probably ahead of some of the developers that they've already hired and that have been working there for a few years already. So learn how to write tests, use the curriculum and the real [00:29:00] world app and things like that.

So I kind of dumped a lot of information and I wanted to quickly recap some of the things that I talked about in this episode.

So the first thing is that testing is really hard, right. But it's also incredibly important. Testing is designed to provide you with the confidence that your application is working correctly. You should start learning how to test by writing end to end test first, because I think those are the easiest to learn and to write.

You should use Cypress and you should use our free, uh, learn.cypress.io curriculum. And, um, you should also read through our real world app. If you wanna learn, that'll literally teach you everything you need to know about how to end to end test and just testing in general, completely for free. You also will get a tremendous amount of benefit and value from reading tests of open source projects that you like or libraries that you like to use.

That's probably hands down. The best way to learn is just by reading other people's tests. [00:30:00] Next once you learn how to test, you need to start writing tests for all of your portfolio projects. And then if you're, when you're interviewing, if a company gives you a take home project, go the extra mile and write tests for that project.

And that will give you a huge leg up in the interview process. So that's it for this episode, guys. I hope you got a lot of value out of it, and I will see you in a couple of weeks. Cheers.


Host Robert Guss is a self-taught front-end developer currently working as a Developer Experience Engineer at Cypress.io. We discuss learning how to code, strategies for getting your first job, web technology news, interviews, testing, and more on this show.

Hosted by

Robert Guss