ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

从ApplicationTest启动时,DataBindingUtil不得返回null

2019-10-26 12:28:35  阅读:375  来源: 互联网

标签:data-binding android-espresso android-databinding android-uiautomator android


运行“ ApplicationTest”时,绑定为NULL,但运行“应用程序”时,绑定正确. This post不起作用.

应用测试

@RunWith(AndroidJUnit4.class)
public class ApplicationTest {

@Rule
public ActivityTestRule<LoadingActivity> mActivityRule =
        new ActivityTestRule<>(LoadingActivity.class);

@Test
public void loginClickMarkerAndUploadDamageReport() {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    //Some initialization code, and then LoginActivity gets started by the App

//This works..
onView(withId(R.id.user_email)).perform(replaceText("some@mail.com"));  

    }
}

登录活动

public class LoginActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final LoginActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
    }
}

activity_login

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <variable
            name="dataSource"
            type="nl.brandmkrs.damageapp.model.User" />
    </data>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:id="@+id/user_email"
        android:text="@{dataSource.password}"/>
</LinearLayout>
</layout>

build.gradle

defaultConfig { 
     minSdkVersion 17
     targetSdkVersion 25
     testInstrumentationRunner     
    "android.support.test.runner.AndroidJUnitRunner"
}
productFlavors {
    // The actual application flavor
    production {
        minSdkVersion 17
    }
    // Test application flavor for UIAutomator tests
    uiTest {
        minSdkVersion 18
    }
}
dataBinding {
    enabled = true
}

enter image description here

输出:

E / MonitoringInstrumentation:nl.brandmkrs.damageapp.view.LoginActivity@d8d4afd遇到异常.将线程状态转储到输出并固定到峡湾.
                                                              java.lang.NullPointerException:尝试从空对象引用中读取字段“ android.widget.VideoView nl.brandmkrs.damageapp.databinding.LoginActivityBinding.videoView”
                                                                  在nl.brandmkrs.damageapp.view.LoginActivity.onCreate(LoginActivity.java:96)

解决方法:

更新中

classpath 'me.tatarka:gradle-retrolambda:3.2.0'

classpath 'me.tatarka:gradle-retrolambda:3.4.0'

解决了问题…

标签:data-binding,android-espresso,android-databinding,android-uiautomator,android
来源: https://codeday.me/bug/20191026/1936254.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有