Unit Testing

Vasiliy Zukanov
A free video tutorial from Vasiliy Zukanov
Professional Android developer, Blogger, Educator
4.7 instructor rating • 7 courses • 24,907 students

Learn more from the full course

Android Unit Testing and Test Driven Development

Unit test your Android applications and reap the benefits of professional test driven development in Android

05:30:57 of on-demand video • Updated August 2020

  • Start unit testing today
  • Practice unit testing with carefully designed exercises
  • Understand Android specific challenges with respect to unit testing
  • Write testable Android applications
  • Understand the benefits of Test Driven Development
  • Get tips for adoption of unit testing on Android projects
English First things first let's talk about what unit testing is. I'll break it into two parts: unit and testing. So, unit. Unit is a container of functionality that has specific responsibility and clearly defined boundary. Ideally, unit should have just one responsibility, but it's far from trivial to achieve that in practice. In Java, classes are the most natural candidates to become units. Testing means ensuring that the thing does what it's supposed to do. As simple as that. So, unit testing can be loosely defined as ensuring that a class does what it's supposed to do. And, again, currently we restrict our discussion to classes, but we will expand that over time. This definition doesn't capture all the aspects and nuances of unit testing, but it's sufficient for our needs at this point. We will refine it as you progress with the course. You test units by invoking their methods and ensuring that they behave according to specification. In other words - you apply a predefined inputs to units and make sure that they produce the expected outputs. Theoretically you can do unit testing without any additional tools. Just write some code that checks production classes. However, in practice, it's much better to rely on unit testing framework. JUnit is the unit testing framework for Java. It's everywhere in Java world. In this course I'm going to use JUnit version 4. There is already version 5, but it's not widely adopted yet. Furthermore, everything you learn in this course is compatible with JUnit 5 as well. That's all the theory you need to know to start with. Let's write some tests now.