Step #4: Renaming Our Unit Test

Our unit test class is named ExampleUnitTest. That is not a particularly useful name for us. Since we will be using this class to test SingleModelMotor, we should rename it to something like SingleModelMotorTest. Typically, a unit test class focuses on testing one main project class, so SingleModelMotorTest would focus on testing SingleModelMotor.

Also, typically, the test class resides in the same package as is the class that it is testing. So, just as SingleModelMotor is in com.commonsware.todo.ui, so should SingleModelMotorTest. However, we do not have a ui sub-package in the test source set — the one that we added earlier is in the main source set.

In the test source set, right-click over the com.commonsware.todo package and choose “New” > “Package” from the context menu. Fill in com.commonsware.todo.ui for the new package name, then click “OK” to create the sub-package.

Next, drag and drop the ExampleUnitTest class from its current location (inside com.commonsware.todo) into this new ui sub-package. As before when we moved around classes, this will bring up a “Move” dialog:

Android Studio Move Dialog
Android Studio “Move” Dialog

Just click the “Refactor” button to complete the move.

Then, right-click over the newly-moved ExampleUnitTest and choose “Refactor” > “Rename” from the context menu. In the “Rename” dialog, fill in SingleModelMotorTest as the new name:

Android Studio Rename Dialog
Android Studio “Rename” Dialog

Then click “Refactor”. This will rename both the file and the Kotlin class, so we now have a SingleModelMotorTest.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.