This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we'll introduce testing in Android and talk about the three different methods of testing we'll be using!
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Hi I'm Ben and in this course we'll
be learning about testing an Android.
0:04
Now I know you've already learned about
testing in Java, but as you may have
0:09
expected, testing in Android requires
a slightly different approach.
0:13
For starters, there's [LAUGH] not really
a clear consensus about how we should
0:18
incorporate testing into our apps.
0:21
So in this course, we'll be going over
three of the most popular choices for
0:23
app tests.
0:27
You'll see exactly how to use each one,
but
0:29
more importantly, you'll learn how each
one takes a different approach to testing.
0:31
So when it comes time to add
tests to your next project,
0:36
you can pick the right
tool right from the start.
0:39
But before we get to the tools,
0:42
let's take a minute to see what's wrong
with our current approach to testing.
0:44
Let's start by downloading the project
we'll be using from GitHub.
0:48
The link is down below
in the teacher's notes.
0:52
There's also a link to a workshop on
how to use GitHub with Android Studio
0:54
in case you need it.
0:59
Let's click Check out project from
Version Control > pick GitHub,
1:01
paste in the Repository URL,
and then hit Clone.
1:06
And hit Yes to check it
out from Version Control.
1:12
Then, it looks like we're having
an error loading three modules.
1:17
Let's choose to keep these.
1:24
Now that we've got the project imported,
1:27
let's take a minute to see
what we'll be testing.
1:29
Let's start by running the app to
first make sure that it works.
1:32
If it doesn't work, it's likely that
the project is referencing something and
1:36
it's build.Gradle file that
isn't installed on your machine.
1:40
All right, here's the app.
1:59
We've got a text view up top and below
is an edit text, a spinner and a button.
2:02
If we change the edit text,
hello world, and
2:09
then click the check,
it updates the text view.
2:14
The spinner updates
the background color and
2:18
the launch activity button launches
this other activity, very exciting.
2:23
As you might have guessed, our goal in
this course will be to successfully test
2:30
each of those three things.
2:34
So changing the added text
should update the text view.
2:35
Selecting a spinner item should
update the background color.
2:42
And clicking the Launch Activity button
should launch this other activity.
2:46
But before we get to the tests,
2:51
let's quickly look through the code
2:56
as well over in main activity.
3:01
We've got the fields for
our views up top, then and
3:05
on create we set our layout,
initialize our views,
3:10
set up the spinner and
then we add our actions to our views.
3:15
Updating the text view when
we change the edit text,
3:22
changing the background color
when we select a spinner item,
3:26
and starting the other activity when
we click the Launch Activity button.
3:32
So far so good.
3:38
In the next video,
we'll start adding some tests.
3:40
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up