December 2013
Beginner
416 pages
12h 45m
English
Another way to test elapsedTime is to refactor the code. You move the current calls to System.currentTimeMillis into a method in its own class. You then replace that class when testing with your own class. Your own class contains a method that returns any current time you want, real or imagined.
In the following, you will refactor the Time class so that it can be tested more easily by the JUnit testing framework.
1. Create a new package in com.androiddevbook.onyourbike named utils, and, inside this package, create a new class named Time. Add a method to the class that returns the current time (see Listing 10.17).
Listing 10.17 Refactoring Current Time into Its Own Class
public ...
Read now
Unlock full access