question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inheritance Support

See original GitHub issue

If mocks and injections are repeated, I like to extract it to a base class. This way, I can repeat same dependencies for other tests without having to repeat. For example:

public abstract class ActivityTest {
    @Rule
    public final MyDaggerMockRule daggerMockRule = new MyDaggerMockRule();

    @Mock
    protected DependencyA mockDependencyA;

    @Named("s1") 
    protected String s1 = "test_string_s1";
    
    @Named("s2")
    @InjectFromComponent
    protected String s2;
}

@RunWith(AndroidJUnit4.class)
@LargeTest
public class AnActivityTest extends ActivityTest {

    @Rule
    public ActivityTestRule<AnActivity> activityTestRule =
            new ActivityTestRule<>(AnActivity.class, true, false);

    @Mock
    DependencyB mockDependencyB;

    @Named("s3")
    @InjectFromComponent
    protected String s3;
    ...
}

Is this supposed to work already? I noticed that we get main app dependencies instead of the ones from defined in the test, particularly in the base class.

PS: This library saves me a lot of headache. Thank you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fabioCollinicommented, Feb 19, 2017

You are right, I added the support for @InjectFromComponent annotated fields in base class in commit fe0c164dad. I’ll release a new version soon. Thanks again for your report

0reactions
rpattabicommented, Feb 22, 2017

Works fine…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inheritance in Java - GeeksforGeeks
In Java, inheritance means creating new classes based on existing ones. ... Reusability: Inheritance supports the concept of “reusability”, ...
Read more >
Inheritance (object-oriented programming) - Wikipedia
Inheritance allows programmers to create classes that are built upon existing classes, to specify a new implementation while maintaining the same behaviors ( ......
Read more >
1.7: OOP Inheritance - Engineering LibreTexts
Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that ......
Read more >
Inheritance in Object Oriented Programming - Analytics Vidhya
Python also supports various types of inheritance in OOPS which I will cover in detail in this article besides covering what is inheritance...
Read more >
Multiple Inheritance
Multiple Inheritance. C++ allows a special kind of inheritance known as multiple inheritance. While most object oriented languages support inheritance, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found