If you've ever spent days chasing a bug in your code
or released an app to the store only to find out
it has performance problems, you will appreciate
the new debugging and testing features
we've added in recent versions of Android Studio.
Let's take a look.
Up first, joining the memory monitor
that was available on Android Studio for some time
is the new CPU monitor.
These tools give you an overview of how running your app
is affecting the device so you can spot performance
problems early.
If you need to get more detailed information,
you can now start Tracking Object allocations,
initiate a memory dump for later analysis,
and even start tracing method calls straight from the IDE.
There's also a new performance captures
pane for quick access to any reports that you've created.
They can be useful when you're trying to find memory leaks
or identify performance critical sections of your app.
But you know what's even better for figuring out where a memory
leak comes from, knowing which pieces of code
hold references to your objects, preventing them
from being garbage collected.
You can see that information instantly
during a life debugging session.
First, start your app using the debug button
or attach to a writing process.
After a successful connection, the IDE
will pause execution on any break points that you specify.
Your can now select the Show referring objects command
on any of the current variables to get the info you need.
And speaking of step-by-step debugging,
have you ever had to use it with some third-party library
where the source code was missing from your project?
Android Studio has you covered with a brand new built-in Java
decompiler.
From now on, whenever you need to check
the internals of a class when all you have is
a JAR file is just one click away in the editor.
And you can even set break points
and do step-by-step debugging inside compiled code.
How cool is that?
One of the other nifty features that come with Android Studio
1.2 is the inlining of values for local variables
right there in the Code Editor when debugging.
So you don't have to look for them in the variables pane.
Also, notice that when you mouse over an operator expression,
you can now see the resulting value in a pop-up
just like when you mouse over variables
to inspect them in more detail.
But you know what the worst thing about debugging
is, it's the debugging itself.
That's why you should be testing your apps in the first place.
And with recent enhancements in our Gradle plug-in and Android
Studio, there's now new ways to write and run automated tests.
Whether you're doing test-driven development
or just want to test your code quickly,
one of the main pain points was having
to deploy test to the device.
And we all know that takes time.
Starting from Android Studio 1.1,
there is support for running unit tests on your development
machine using the local JVM.
To use this feature, first put your JUnit tests
in the test folder on your Android module.
Gradle will create a special version
of Android JAR in the class path when you run the test task.
Be aware that this JAR doesn't actually contain working code,
so you can't use any framework classes.
You should use one of the popular mocking libraries
like MOckito to mock the Android dependencies that you need.
For tests that need to run on the device
where the full framework is required,
you can use the Android test source set.
These tests will be deployed alongside your app
and run on the target device or emulator.
While not technically part of Android Studio or Gradle,
we have recently released a library
that contains many classes that can help you with writing
and running your tests.
It's called the Android Testing Support Library.
And it's available through the Android Support Repository.
It gives you the most up-to-date testing frameworks and APIs
made by Google, including an Android Test Runner with JUnit
for support, the Espresso library
for functional UI testing, the UIAutomator, and more.
To find out how to set up your project for running tests
using the Android Testing Support Library,
follow these links and check out our documentation and samples.
If you have any questions or suggestions regarding debugging
apps using Android Studio, you can join the discussion
in our Google+ community.
See ya.
[MUSIC PLAYING]