I have a class that extends from ServiceTestCase
to test my Android Service implementation.
public class MainCoreServiceTest extends ServiceTestCase<CoreService> {
protected static final String DB_PATH = "/data/data/"
+ CoreService.class.getPackage().getName() + "/databases/"
+ DatabaseManager.DB_NAME;
// More code
}
The problem I am facing is that if I run only one test method, everything is fine, but if I launch the whole class (which contains several test methods) then on second test method I get an ExceptionInInitializerError
and I found out this is because of DB_PATH
being null. This is the method where this happens:
private void wipeOutDB() {
// Erase DB file
File dbFile = new File(DB_PATH);
if (dbFile.exists()) {
assertTrue(dbFile.delete());
}
// Erase journal file
dbFile = new File(DB_PATH + "-journal");
if (dbFile.exists()) {
assertTrue(dbFile.delete());
}
}
new File(DB_PATH)
obviously fails when DB_PATH
is null
I don't modify this constant anywhere (anyway I can't modify it because it's final), so I don't understand this behavior.
If I move this constant to another class/interface, it works fine.
Can anyone please explain this behavior? Thanks in advance!