jeudi 3 décembre 2015

Application class not created during tests after migrating from Eclipse to Android Studio

I have an Android project with Robotium/Junit tests, working fine on Eclipse, but after migrating to Android Studio 1.5, tests which are using the application context are crashing.

public class App extends Application
@Override
public void onCreate()
{
    super.onCreate();
    mInstance = this;
}

public static synchronized App getInstance()
{
    return mInstance;
}

And in test:

App.getInstance().getSharedPreferences("prefs",Context.MODE_PRIVATE);

The App.getInstance() always return null, while launching from Android Studio, and on Eclipse it is ok.

I have the Application class name specified correctly in the AndroidManifest file.

Aucun commentaire:

Enregistrer un commentaire