Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!