Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9214287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:56:33+00:00 2026-06-18T01:56:33+00:00

I try to use Robolectric to run tests for my Android application, which is

  • 0

I try to use Robolectric to run tests for my Android application, which is using the android-support package. In my onCreate() method I call

getSupportLoaderManager().initLoader(0, null, this);

Unfortunately, getSupportLoaderManager() returns null here. Do I have to prepare anything to make the compatiblity classes available to robolectric?

I have the android.jar (android-8) and the android-support-v4.jar in the classpath in my test project, along with robolectric-1.2 snapshot version.

Test class:

@RunWith(RobolectricTestRunner.class)
public class HoebAppActivityTest {

    @Test
    public void shouldStartActivity() {
            final MyActivity activity = new MyActivity();
            System.out.println(activity.getSupportLoaderManager()); // return null

            activity.onCreate(null);
    }
}

Edit:

System.out.println(Robolectric.directlyOnFullStack(activity)
            .getSupportLoaderManager());

outputs android.support.v4.app.LoaderManagerImpl@9a90b9 so I guess, I just need to feed this back to the activity? Seems like I am getting closer here.

Edit2: I tried to bind my own ShadowFragmentActivity:

@Implements(FragmentActivity.class)
public class ShadowFragmentActivity extends
    com.xtremelabs.robolectric.shadows.ShadowFragmentActivity {
@RealObject
private FragmentActivity realActivity;

@Implementation
public LoaderManager getSupportLoaderManager() {
    return Robolectric.directlyOnFullStack(realActivity)
            .getSupportLoaderManager();
}
}

bound with

Robolectric.bindShadowClass(ShadowFragmentActivity.class);

This appears to work for the moment. I will have to try further to see if it does what I want. No idea if this is in any way the correct way to go or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:56:35+00:00Added an answer on June 18, 2026 at 1:56 am

    Robolectric 1.x had poor support for the Android support library. Robolectric 2.0 is significantly better, and has full support for fragments. An alpha was just released today:

    <dependency>
      <groupId>org.robolectric</groupId>
      <artifactId>robolectric</artifactId>
      <version>2.0-alpha-1</version>
    <dependency>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm trying to use the maven android plugin and robolectric to get tests
When I'm taking my query using Ajax on jQuery, o try use the method
I try to use the great particle emitter which Michael Daley build for his
i try to use TBXML and getting this error TBXML class method +tbXMLWithURL not
I try to use fragments with AndroidAnnotations and maven. It worked with Android 4.0+
I have a problem with Automapper when I try use custom resolver which uses
I am trying to use HTML::WikiConverter::MediaWiki which I have installed using yum install perl-HTML-WikiConverter-MediaWiki.noarch
I aim to try use DevExpress web server controls (which are awesome) in an
I'm using robolectric to test an activity that makes use of Google Analytics. Unfortunately,
I try use gssapi32.dll in my application but I receive exception when app start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.