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