08 Teach : Team Activity
Unit Testing in Android
Objectives
Write some unit tests for your android project.
Overview
This week, you'll be writing unit tests for your team project. In the spirit of TDD, it's perfectly acceptable if all of the tests fail. As long as they can compile and run, you are good.
Instructions
The following steps will guide you through this process.
Part I - Make sure you can run unit tests.
-
Follow the instructions in the "Setting Up Your Test Environment" section of the Local Unit Tests documentation to make sure the JUnit dependency is correctly added to your project.
-
To make sure everything is working correctly, create a unit test in the ExampleUnitTest class provided by Android Studio that will always pass. Something like:
assertEquals(4, 2 + 2);
-
Run the test and make sure everything works.
Part II - Add some real unit tests to your project.
-
Brainstorm with your group some possible unit tests for your project. Model and Controller classes are good candidates for unit tests.
Try to think of it in terms of "If this function received this input, what should the output always be?"
Write at least three unit tests for your project. Again, they don't have to pass at this point, but they should compile and run.
Congratulations! You now know how to write unit tests for Android projects.
Make sure to complete the accompanying quiz for this assignment on I-Learn.