我如何在Android中进行测试?

我如何在Android中进行测试?,android,junit,Android,Junit,我正在搜索Android中的测试,但我没有找到我想要的,所以我需要问你这个问题。我想创建一个模拟发送表单的clase。我有这个,但我有一个错误: package net.elinformaticoenganchado.sergio.crossfighters; import android.view.View; import android.widget.Button; import android.widget.EditText; import net.elinformaticoenganch

我正在搜索Android中的测试,但我没有找到我想要的,所以我需要问你这个问题。我想创建一个模拟发送表单的clase。我有这个,但我有一个错误:

package net.elinformaticoenganchado.sergio.crossfighters;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import net.elinformaticoenganchado.sergio.crossfighters.Configuration.ConfigurationEdit;

import org.junit.Test;

/**
 * @author Sergio Herrero Cruz <sergioherre96@gmail.com>
 * @package net.elinformaticoenganchado.sergio.crossfighters
 */
public class ConfigurationTest {

    @Test
    public void add_values(){
        ConfigurationEdit configurationEdit = new ConfigurationEdit();

        View v = configurationEdit.getView();

        EditText name = (EditText) v.findViewById(R.id.configuration_edit_name_edit);
        EditText phrase = (EditText) v.findViewById(R.id.configuration_edit_phrase_edit);

        name.setText("NombreTest");
        phrase.setText("PhraseTest Phrase Test");

        Button save = (Button) v.findViewById(R.id.configuration_edit_button_save);
        save.performClick();

    }
}
package net.elinformaticoenganchado.sergio.crossfighters;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入net.elinformaticoenganchado.sergio.crossfighters.Configuration.ConfigurationEdit;
导入org.junit.Test;
/**
*@作者Sergio Herrero Cruz
*@package net.elinformaticinganchado.sergio.crossfighters
*/
公共类配置测试{
@试验
公共void添加_值(){
ConfigurationEdit ConfigurationEdit=新建ConfigurationEdit();
View v=configurationEdit.getView();
EditText名称=(EditText)v.findViewById(R.id.configuration\u edit\u name\u edit);
EditText短语=(EditText)v.findViewById(R.id.configuration\u edit\u phrase\u edit);
name.setText(“NombreTest”);
短语.setText(“短语测试短语测试”);
按钮保存=(按钮)v.findViewById(R.id.configuration\u edit\u Button\u save);
save.performClick();
}
}
这是我的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    >

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/configuration_edit_name"
            android:textSize="@dimen/general_text_size"
            android:textStyle="bold"
            android:id="@+id/configuration_edit_name_text"
            />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/configuration_edit_name_text"
            android:hint="@string/configuration_edit_name_hint"
            android:id="@+id/configuration_edit_name_edit"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/configuration_edit_name_edit"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:text="@string/configuration_edit_phrase"
            android:textSize="@dimen/general_text_size"
            android:textStyle="bold"
            android:id="@+id/configuration_edit_phrase_text"
            />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/configuration_edit_phrase_text"
            android:hint="@string/configuration_edit_phrase_hint"
            android:id="@+id/configuration_edit_phrase_edit"
            />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/configuration_edit_phrase_edit"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:text="@string/configuration_edit_button"
            android:textSize="@dimen/general_text_size"
            android:textStyle="bold"
            android:background="@color/colorSave"
            android:id="@+id/configuration_edit_button_save"
            />

    </RelativeLayout>

</ScrollView>

错误是:

位于的java.lang.NullPointerException net.elinformaticoenganchado.sergio.crossfighters.ConfigurationTest.add_值(ConfigurationTest.java:25) 位于的sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 位于java.lang.reflect.Method.invoke(Method.java:606) org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:50) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:47) 在 org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)位于 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)位于 org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)位于 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)位于 org.junit.runners.ParentRunner.run(ParentRunner.java:363)位于 org.junit.runner.JUnitCore.run(JUnitCore.java:137)位于 JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) 在 com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) 在 com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) 位于的sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 位于java.lang.reflect.Method.invoke(Method.java:606) com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)


谢谢你的帮助

什么是配置编辑?如何运行测试用例?android开发库大多包含存根,因此您不能(没有其他帮助,如)在开发机器上运行涉及android库的测试。@dhke是活动。嗯,我不知道robolectric,我会试试。什么是
ConfigurationEdit
?如何运行测试用例?android开发库大多包含存根,因此您不能(没有其他帮助,如)在开发机器上运行涉及android库的测试。@dhke是活动。嗯,我不知道机器人分子,我会试试。