Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda