小编Cor*_*ott的帖子

使用Robolectric测试ViewPager(和CursorLoader)

有谁知道如何使用Robolectric测试以下设置?

包含ViewPager的片段,使用CursorLoader加载的数据.

使用下面的代码,CursorLoader永远不会被推入视图寻呼机的适配器中.我被await()电话困住了.

EventsFragmentTest.java:

@RunWith(CustomRobolectricTestRunner.class)
public class EventsFragmentTest extends AbstractDbAndUiDriver
{
    // which element in the view pager we are testing
    private static final int           TEST_INDEX = 0;

    protected SherlockFragmentActivity mActivity;
    protected EventsFragment_          mFragment;

    @Override
    @Before
    public void setUp() throws Exception
    {
        // create activity to hold the fragment
        this.mActivity = CustomRobolectricTestRunner.getActivity();

        // create and start the fragment
        this.mFragment = new EventsFragment_();
    }

    @Test
    public void sanityTest()
    {
        // create an event
        final Event event = this.createEvent();

        // …
Run Code Online (Sandbox Code Playgroud)

android robolectric android-testing android-cursorloader

91
推荐指数
1
解决办法
3583
查看次数

在android中将位图转换为jpeg

有没有办法将android.graphics.Bitmap实例转换为android中的jpeg?

android jpeg bitmap

14
推荐指数
1
解决办法
2万
查看次数

IntelliJ IDE中是否有"Do Refactor"(重构预览窗格)的键盘快捷键?

当您尝试在(PHP,Java ..)代码中尝试折射某些方法时,如何按"Do refractor"按钮.

脚步:

  • 按ctrl + r重命名方法
  • 更改名称然后按Enter键
  • 然后另一个面板显示该方法的用法和"Do Refactor"按钮

有没有办法在不使用鼠标的情况下按"Do Refactor"?

intellij-idea intellij-14

13
推荐指数
2
解决办法
1737
查看次数

如何减少以下代码的"Cyclomatic Complexity"

我想知道如何减少以下代码的Cyclomatic Complexity,如果这是我应该担心的事情.

请参考方法ValuePojo.getSomething()(请不要担心变量命名,为了清楚起见,这个问题已重写)

public class ValuePojo
{
    private ValueTypeEnum type;

    private BigDecimal    value1;

    private BigDecimal    value2;

    private BigDecimal    value3;

    public ValuePojo()
    {
        super();
    }

    /**
     * This method reports as "HIGH Cyclomatic Complexity"
     * 
     * @return
     */
    public BigDecimal getSomething()
    {
        if (this.type == null)
        {
            return null;
        }

        switch (this.type)
        {
            case TYPE_A:
            case TYPE_B:
            case TYPE_C:
            case TYPE_D:
                return this.value1;

            case TYPE_E:
            case TYPE_F:
            case TYPE_G:
            case TYPE_H:
                return this.value2;

            case TYPE_I:
            case TYPE_J:
                return this.value3;
        }

        return …
Run Code Online (Sandbox Code Playgroud)

java code-complexity

6
推荐指数
2
解决办法
2万
查看次数

Android Espresso vs Actionbar

我一直在尝试使用Espresso测试一个带有菜单抽屉的应用程序.

现在为了陌生.

在第一次测试中,我打开抽屉并单击一个项目,然后继续进行剩下的测试.一切都很好.

当我添加第二个完全相同的测试时,我得到一个例外.它似乎与菜单抽屉的内容有关,但我不知所措.

例外是这样的:

com.google.android.apps.common.testing.ui.espresso.PerformException: Error performing 'single click' on view '(with id: is <2131099739> and with text: is "Events")'.
at com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.build(PerformException.java:67)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:57)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:146)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:77)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:69)
at com.xxx.app.events.StackOverflowExampleTest.selectMenu(StackOverflowExampleTest.java:83)
at com.xxx.app.events.StackOverflowExampleTest.setUp(StackOverflowExampleTest.java:72)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:177)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:119)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1608)
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
at least 90 percent of the view's area is displayed to …
Run Code Online (Sandbox Code Playgroud)

testing android android-espresso

4
推荐指数
1
解决办法
6359
查看次数

带有文字和图像的Android按钮

在看到这个功能的许多问题并尝试按照答案后,我想知道是否有更清晰的例子?

编辑:我试图制作一个大按钮,其图像和文字位于"中间".它必须表现为按钮(StateList drawable),图像/文本对应该分组并居中(作为一个组)

android button

3
推荐指数
1
解决办法
1万
查看次数