Android 使用RoboGuice+测试放射组时遇到问题;生物分子

Android 使用RoboGuice+测试放射组时遇到问题;生物分子,android,tdd,radio-group,roboguice,robolectric,Android,Tdd,Radio Group,Roboguice,Robolectric,我用了很多不同的方法来看待这个问题,用我剩下的一点点头发,我想我会把它放在那里,希望有人已经试过了 我正在尝试为我的支持机器人向导的活动编写一个机器人分子测试。具体地说,我正试图编写一个测试来确保一个放射组的行为 问题在于,在运行测试时,RadioGroup的行为与RadioGroup不同,它一次只执行一个RadioButton-checked行为。通过断言和使用调试器,我可以看到我可以同时检查组中的所有三个按钮 RadioGroup非常简单: <RadioGroup androi

我用了很多不同的方法来看待这个问题,用我剩下的一点点头发,我想我会把它放在那里,希望有人已经试过了

我正在尝试为我的支持机器人向导的活动编写一个机器人分子测试。具体地说,我正试图编写一个测试来确保一个放射组的行为

问题在于,在运行测试时,RadioGroup的行为与RadioGroup不同,它一次只执行一个RadioButton-checked行为。通过断言和使用调试器,我可以看到我可以同时检查组中的所有三个按钮

RadioGroup非常简单:

<RadioGroup
    android:id="@+id/whenSelection"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RadioButton
        android:id="@+id/whenToday"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/today" />

    <RadioButton
        android:id="@+id/whenYesterday"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/yesterday" />

    <RadioButton
        android:id="@+id/whenOther"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/earlier" />

</RadioGroup>
但是,发生的情况是最后一个断言失败,调试器确认第一个按钮在当天仍然处于选中状态

以下是完整的测试类:

@RunWith(InjectedTestRunner.class)
public class MyTest {
    @Inject ActivityLogEdit activity;

    RadioButton whenToday;
    RadioButton whenYesterday;
    RadioButton whenOther;

@Before
public void setUp() {
    activity.setIntent(new Intent());
    activity.onCreate(null);

    whenSelection = (RadioGroup) activity.findViewById(R.id.whenSelection);
    whenToday = (RadioButton) activity.findViewById(R.id.whenToday);
    whenYesterday = (RadioButton) activity.findViewById(R.id.whenYesterday);
    whenOther = (RadioButton) activity.findViewById(R.id.whenOther);       
}

@Test
public void checkDateSelectionInitialState() throws Exception {
    Assert.assertTrue(whenToday.isChecked());
    Assert.assertFalse(whenYesterday.isChecked());
    Assert.assertFalse(whenOther.isChecked());
    Assert.assertEquals(View.GONE, logDatePicker.getVisibility());

    whenYesterday.performClick();

    Assert.assertTrue(whenYesterday.isChecked());
    Assert.assertFalse(whenToday.isChecked());
  }
}
我已经尝试了我能想到的所有不同的方法。我觉得我在做一些愚蠢的事情,或者缺少一些基本的概念。请帮忙


Andrew

我收到了一份关于机器人分子小组的帖子的回复,该帖子是由开发该小组的其中一位成员撰写的:

您正在谈论的功能(选中单选按钮)将 取消选中组中的所有其他单选按钮)尚未实现 在机器人分子中。请随时提交功能请求: 如果我没记错,请尝试将测试更改为使用 RadioGroup上的getCheckedRadioButtonId()而不是上的isChecked() 单选按钮——我相信已经实现了

请注意,我还尝试了
getCheckedRadioButtonId()
,但它也没有实现(总是返回-1)

安德鲁

@RunWith(InjectedTestRunner.class)
public class MyTest {
    @Inject ActivityLogEdit activity;

    RadioButton whenToday;
    RadioButton whenYesterday;
    RadioButton whenOther;

@Before
public void setUp() {
    activity.setIntent(new Intent());
    activity.onCreate(null);

    whenSelection = (RadioGroup) activity.findViewById(R.id.whenSelection);
    whenToday = (RadioButton) activity.findViewById(R.id.whenToday);
    whenYesterday = (RadioButton) activity.findViewById(R.id.whenYesterday);
    whenOther = (RadioButton) activity.findViewById(R.id.whenOther);       
}

@Test
public void checkDateSelectionInitialState() throws Exception {
    Assert.assertTrue(whenToday.isChecked());
    Assert.assertFalse(whenYesterday.isChecked());
    Assert.assertFalse(whenOther.isChecked());
    Assert.assertEquals(View.GONE, logDatePicker.getVisibility());

    whenYesterday.performClick();

    Assert.assertTrue(whenYesterday.isChecked());
    Assert.assertFalse(whenToday.isChecked());
  }
}