Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
Robolectric Creating Dummy SharedPreferences of a Different Application

I have searched through posts here as well as Google for a solution to a problem that I am having with doing unit tests using Robolectric. One thing that I need to test involves looking up the shared preferences file that resides within another application. So, I don't need to generate/create/lookup the shared preferences file on the activity I am testing, I need the shared preferences file that resides in a different application. So, I need to trick the environment by thinking that this file exists for that application. So TLDR

  1. App1 performing unit tests on
  2. App1 accesses SharedPreferences of App2

Need to generate fake SharedPreferneces file of App2 so App1 can access and continue on with tests. Any help is appreciated. Thank you!.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I would first rework the code to achieve next:

  1. You have a class that works with any SharedPreferences file
  2. You have a class that opens/copy file for another application
  3. You have a class that orchestrate this by providing output of file reading class to shared preference processor class

And then the unit test would look like:

  1. Check if shared preferences class does required operations
  2. Check that class that copies/reads file from one location to another 3a. Check that orchestrator class pass correct paths to file operations class 3b. Check that orchestrator class pass result (stream, string, etc) to shared preferences class

Hope it helps!

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda