Testing files, databases, and content providers
Some test cases have the need to exercise databases or ContentProvider
operations, and soon comes the need to mock these operations. For example, if we are testing an application on a real device, we don't want to interfere with the normal operation of applications on the said device, especially if we were to change values that may be shared by more than one application.
Such cases can take advantage of another mock class that is not a part of the android.test.mock
package but of android.test
instead, namely RenamingDelegatingContext
.
Remember, this class lets us mock file and database operations. A prefix supplied in the constructor is used to modify the target of these operations. All other operations are delegated to the delegating Context that you specify.
Suppose our Activity under test uses some files or databases that we want to control in some way, probably to introduce specialized content to drive our tests, and we don't want to, or we...