2

In my case getVersion in Robolectric SQLiteOpenHelper returns always 0. Because of this onCreate is called in DBHelper if the current DATABASE_VERSION is for example greater than 0.

Does anyone know how to configure/set the Database-Version in Robolectric? I am using robolectric-1.1-jar-with-dependencies.jar and roboguice-2.0b4.jar. (Read + write works so far...)

thx

Mike Mitterer
  • 6,810
  • 4
  • 41
  • 62

1 Answers1

2

Uhhhh found out how cool Robolectric is - so I have to answer my own question. Here is what I did:

ShadowSQLiteDatabase.java:

@Implements(SQLiteDatabase.class)
public class ShadowSQLiteDatabase extends com.xtremelabs.robolectric.shadows.ShadowSQLiteDatabase {

    @Implementation
    public int getVersion() {
        return 10;
    }
}

InjectedTestRunner.java:

public class InjectedTestRunner extends RobolectricTestRunner {
    ...
    @Override
    protected void bindShadowClasses() {
        Robolectric.bindShadowClass(ShadowSQLiteDatabase.class);
    }
}

That's it!

Mike Mitterer
  • 6,810
  • 4
  • 41
  • 62