2

我在将 Robolectric 与 ActionBarSherlock 一起使用时遇到了很大的问题。

我不知道为什么,但似乎 Roboletric 找不到一类:

例外:

java.lang.RuntimeException: java.lang.NoSuchMethodException: android.support.v4.app.Watson.$$robo$$Watson_7e47___constructor__()
    at java.lang.Class.getDeclaredMethod(Class.java:1937)
    at org.robolectric.bytecode.ShadowWrangler$InvocationPlan.callOriginal(ShadowWrangler.java:589)
    at org.robolectric.bytecode.ShadowWrangler.methodInvoked(ShadowWrangler.java:185)
    at org.robolectric.bytecode.RobolectricInternals.methodInvoked(RobolectricInternals.java:118)
    at android.support.v4.app.Watson.__constructor__(Watson.java)
    at android.content.Context.<init>(Context.java)
    at android.content.ContextWrapper.<init>(ContextWrapper.java)
    at android.view.ContextThemeWrapper.<init>(ContextThemeWrapper.java)
    at android.app.Activity.<init>(Activity.java)
    at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java)
    at android.support.v4.app.Watson.<init>(Watson.java)
    at com.actionbarsherlock.app.SherlockFragmentActivity.<init>(SherlockFragmentActivity.java:21)
    at pl.activities.CoreFragmentMenuActivity.<init>(CoreFragmentMenuActivity.java:21)
    at pl.activities.CoreNavigationActivity.<init>(CoreNavigationActivity.java:16)
    at pl.activities.MainActivity.<init>(MainActivity.java:18)
    at MainActivityTest.setUp(MainActivityTest.java:20)

测试类:

@RunWith(CustomTestRunner.class)
public class MainActivityTest
{
    private MainActivity activity;
    private Button pressMeButton;
    private TextView results;

    @Before
    public void setUp() throws Exception
    {
        activity = new MainActivity();
        activity.onCreate(null);

    }

    @Test
    public void shouldUpdateResultsWhenButtonIsClicked() throws Exception
    {
        Assert.assertEquals(activity.getTitle(), activity.getResources().getString(R.string.activity_main_title));
    }
}

CustomTestRunner:

import java.io.File;

public class CustomTestRunner extends RobolectricTestRunner
{
    public CustomTestRunner(Class<?> testClass) throws InitializationError
    {
        super(RobolectricContext.bootstrap(CustomTestRunner.class, testClass,
                new RobolectricContext.Factory()
                {
                    @Override
                    public RobolectricContext create()
                    {
                        return new RobolectricContext()
                        {
                            //http://stackoverflow.com/questions/15603583/impossible-runtimeexception-stub-with-robolectric
                            @Override
                            public boolean useAsm() // this override does the trick
                            {
                                return false;
                            }

                            @Override
                            protected AndroidManifest createAppManifest()
                            {
                                return new AndroidManifest(
                                        new File("AndroidManifest.xml"),
                                        new File("res"));
                            }
                        };
                    }
                }));
    }

我在用:

<dependency>
         <groupId>org.robolectric</groupId>
         <artifactId>robolectric</artifactId>
         <version>2.0-alpha-2</version>
         <scope>test</scope>
</dependency>

有没有人有类似的问题?

4

1 回答 1

0

我不知道你是否遇到过,但 Robolectric 发布了一篇关于与 ABS 兼容性的博客文章。检查出来。希望它能解决您的问题。

于 2013-05-29T02:41:49.007 回答