We can test many aspects of our software, from a single function’s return value, to complete user stories. In this video we’ll narrow in on the kind of testing we’ll do most: unit testing.
You run unit tests constantly during the development process to ensure that everything is working, every time you make a change.
You use integration tests when you add new code to pre-existing code, to make sure that not only do all of the pieces work individually as expected, but also that they run together correctly without breaking.
Run your application from start to finish for all the user stories you can think of. This ensures that the program is ready to go live, and that the special details of deployment do not mess up the code you carefully tested on your local machine with unit tests and integration tests. You conduct end-to-end tests occasionally, maybe only a few times during a product’s life-cycle, as they are very time consuming and expensive.
The kind of automated test we'll learn to write in this course 0:00 are called, Unit Tests. 0:03 Unit Testing involves Writing tests that confirm an individual function or 0:05 piece of code works the way we want it to. 0:10 We write Unit Test for code that has a clear specific purpose, for example, 0:13 we'll often write unit test for the individual functions in a program, 0:18 the unit tests can then call the function without needing to run our entire 0:22 application to make sure we know that the function behaves as we expect. 0:26 Unit Tests are kind of like a basketball drill. 0:31 As a basketball player, you need to master various skills like shooting, 0:34 passing, running, dribbling and so on. 0:38 Basketball players run specific drills to test 0:41 each of these skills outside of an actual game. 0:44 A basketball player might just practice free throws for a while and 0:47 then practice dribbling at a different time without worrying about shooting or 0:51 passing or what their teammates are doing. 0:55 A Unit Test is like one of these drills and 0:58 we can run unit tests constantly during our development process 1:00 to ensure that everything is working every time we make a change. 1:04 But being good at each single thing isn't enough to be 1:08 a really good basketball player. 1:11 They also have to be able to do them all together. 1:13 In addition to practicing each individual basketball skill, 1:16 players practice drills as a team. 1:19 They need to make sure that they can dribble, pass, and 1:21 shoot just as well when there are other people doing their part around them. 1:24 And that they can do them all together in the correct sequence. 1:29 In programming this kind of testing is called Integration Testing. 1:33 You use integration tests when you add new code to preexisting code 1:36 to make sure that not only do all of the pieces work individually as expected, but 1:41 also that they run together correctly without breaking. 1:45 Product managers or people who run open-source projects might also run 1:49 integration tests whenever others write code to contribute to their projects. 1:53 To make sure that the code others write doesn't break their existing project 1:58 that's useful. 2:02 On a basketball team it's not enough that your skills are up to par. 2:03 And that you work well together as a team. 2:07 You also have to play actual games. 2:09 Live games are very different even from practice games, 2:12 we play basketball on different courts. 2:16 With different crowds and against teams with different strategies. 2:18 So being a good basketball team requires a lot of team experience in this context. 2:22 In software, this kind of testing is called End-To-End Testing. 2:29 We fire up the application and 2:33 run it from start to finish for all the user stories we can think of. 2:34 This ensures that the program is ready to go live. 2:38 And that the special details of deployment don't screw up the stuff that we 2:41 carefully tested on our local machines with Unit Test and integration tests. 2:46 We conduct end to end test very occasionally. 2:51 Maybe only a few times during a product's life cycle. 2:53 As a very time consuming and expensive. 2:56 You might conduct some or all of these kind of tests where you work or 2:59 in your personal projects. 3:03 We'll focus on Unit Testing in this course because that's what you'll spend most of 3:04 the time writing. 3:08 Unit Tests actually help us write better code and 3:10 grow as developers as soon as we start using them. 3:13
You need to sign up for Treehouse in order to download course files.Sign up