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 7952149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:46:29+00:00 2026-06-04T02:46:29+00:00

I haven’t found any examples on how to do this. I’m assuming it is

  • 0

I haven’t found any examples on how to do this. I’m assuming it is not possible based on examples like this:

@Bean(MyImplementation.class)
MyInterface myInterface;

where the class to inject is already determined.

  • 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-04T02:46:31+00:00Added an answer on June 4, 2026 at 2:46 am

    The question is, are you unit testing or integration testing?

    If you are unit testing, I would suggest using mocks the old fashioned way, by using a setter and trying to test the Java code without the dependency injection framework involved. This will test your class in isolation and sidesteps a lot of complexity.

    What I mean:

    public class Test{
    
        ClassInTest inTest;
        MyInterface myInterface;
    
        @Before
        public void setup(){
             inTest = new ClassInTest();
             //or your favorite mocking frameowrk
             myInterface = EasyMock.createMock(MyInterface.class);  
             inTest.setMyInterface(myInterface);
        }
    
        @Test
        public void testMethod(){
            //...mocking test code
        }
    }
    

    Of course, testing Android Activities (and other extensions of Android) is difficult because of the exception throwing stubs and final classes/methods. This is where Robolectric comes in handy (and highly recommended) for instantiating/shadowing the Android API.

    If you are integration testing you may want to take another approach. Personally, I would try not to mock during integration tests as I try to test the application as it would run in production. But, if you really want to mock, you could use a similar approach to unit testing and introduce a mock after you stand up your generated Activity class. Worth noting, you can perform integration tests directly on the hardware using frameworks like Robotium.

    More to your question, I am not aware of any facilities of AndroidAnnotations specifically for injecting Mocks or introducing Mocks into the injected dependency tree of an application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't found any documentation on this or seen this done before, but is
I haven't found any information on MSDN regarding this problem. If we create an
I haven't found this question, feel free to close if it's already up here.
I haven't found any references to apps that use a custom activity indicator --
I haven't been able to find any real documentation on this, so I'm wondering
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Haven't found this in my search on Stackoverflow - I know I've seen a
Actually haven't found the answer for this one. What for and why do i
I haven't found a question on this topic so I'll ask. I've never actually
Haven't found in docs. Does java ResultSet supports query arguments,like jdbcTemplate? For example, something

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.