I need to test some function, that needs my application’s database and context.
I used to implement my testcase like this:
// TestCase is in the same package with tested module
package com.ircos.andromeda.utils;
...
// database operation classes
import com.ircos.andromeda.database.MeasurementDbAdapter;
import com.ircos.andromeda.database.SessionDbAdapter;
import com.ircos.andromeda.database.domain.Measurement;
import com.ircos.andromeda.database.domain.Session;
import com.ircos.andromeda.exceptions.ExportException;
public class SessionExportHelperTestCase extends AndroidTestCase {
...
So, I thought context, retrieved by getContext() should return my application’s context and I’d be able to use the database just like from application itself.
But I failed. What am I doing wrong?
protected void setUp() {
sessionDbAdapter.open(); // exception fires here!
…
public void open() throws SQLiteException {
if (isOpen())
return;
this.open(new DatabaseManagementHelper(this.ctx)); // context is null!
}
Presumably, you have not assigned
getContext()tothis.ctx, and sothis.ctxremainsnull.