Traxex1909
Traxex1909

Reputation: 2710

Robolectric - RuntimeException Stub

I have a Robolectric test case written as

public void setUp(){
    mActivity = new CalcActivity();
    ShadowActivity shadow = Robolectric.shadowOf(mActivity);

//more code 

But i'm getting a RuntimeException : Stub! at the very start of the setUp method.

java.lang.RuntimeException: Stub!
at android.content.Context.<init>(Context.java:4)
at android.content.ContextWrapper.<init>(ContextWrapper.java:5)
at android.view.ContextThemeWrapper.<init>(ContextThemeWrapper.java:5)
at android.app.Activity.<init>(Activity.java:6)
at com.example.advancedcalc.CalcActivity.<init>(CalcActivity.java:13)
at com.example.CalcActivityTest.setUp(CalcActivityTest.java:25)

CalcActivity implements an OnclickListener and it has a bunch of other methods that perform basic calculator operations inside.

Can anyone tell me why i'm getting java.lang.RuntimeException: Stub! and how to deal with it ?

Upvotes: 2

Views: 1645

Answers (2)

Chisko
Chisko

Reputation: 3107

In my case I was using assertions from junit.framework.Assert and changing to org.junit.Assert did the trick

Upvotes: 0

MaciejG&#243;rski
MaciejG&#243;rski

Reputation: 22232

Have you added

@RunWith(RobolectricTestRunner.class)

as an annotation to your test class?

Upvotes: 7

Related Questions