代码之家  ›  专栏  ›  技术社区  ›  gmmo

RoboMetric无法使自定义对话框可见

  •  0
  • gmmo  · 技术社区  · 7 年前

    无论如何,代码非常基本,基于以下线程:

    How to create a Custom Dialog box in android?

    以下是我的应用程序代码:

    public class CustomDialog extends DialogFragment {
        public Dialog mCustomDialogTest;
        public EditText mEditText;
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            mCustomDialogTest = new Dialog(getActivity());
            mCustomDialogTest.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
            mCustomDialogTest.getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
            mCustomDialogTest.setContentView(R.layout.custom_dialog);
            mCustomDialogTest.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            mEditText = (EditText) mCustomDialogTest.findViewById(R.id.edit_text_id);
            return mCustomDialogTest;
        }
    }
    

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <EditText
            android:id="@+id/edit_text_id"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:hint="@string/app_name"
            android:inputType="text" />
    </LinearLayout>
    

    @Test
    public void testCustomDialog() {
        CustomDialog customDialog = new CustomDialog();
        customDialog.show(mActivity.getFragmentManager(), getClass().getName());
    
        boolean visible = customDialog.isVisible(); //This never works :(
        Assert.assertTrue("Dialog is visible", visible);
    }
    

    它总是声称它不可见:(然而,代码在设备上运行良好。

    以下是gradle中的相关部分:

        testOptions {
            unitTests {
                includeAndroidResources = true
            }
        }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        testImplementation 'androidx.test.espresso:espresso-core:3.1.0'
        testImplementation 'androidx.test:core:1.0.0'
        testImplementation 'androidx.test.ext:junit:1.0.0'
        testImplementation 'junit:junit:4.12'
        testImplementation 'org.mockito:mockito-core:2.23.0'
        testImplementation 'org.robolectric:robolectric:4.0.2'
        androidTestImplementation 'com.google.truth:truth:0.42'
        testImplementation 'com.google.truth:truth:0.42'
        androidTestImplementation 'com.android.support.test:rules:1.0.2'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
    }
    

    有人能帮我吗?对于单元测试,我完全停留在最基本的功能上。

    非常感谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Jujhar Singh    7 年前

    尝试使用 getUserVisibleHint isVisible 方法