在我的Robolectric测试中,我编写了一个<p>标签。
@Rule
public ActivityScenarioRule<AppCompatActivity> activityScenarioRule =
new ActivityScenarioRule<>(AppCompatActivity.class);
@Rule
public ActivityScenarioRule<FragmentUtilActivity> activityScenarioRule2 =
new ActivityScenarioRule<>(FragmentUtilActivity.class);
以及一个内部类:
private static class FragmentUtilActivity extends FragmentActivity {
public static int anchorId = 200;
private StandaloneAccountMenuDialogFragment<FakeAccount> dialogFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout view = new LinearLayout(this);
view.setId(anchorId);
setContentView(view);
}
}
但是当我运行代码时,它失败了。
第一条规则为什么有效,而第二条却无效?
Unable to resolve activity for Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.myComp..internal/.StandaloneAccountMenuDialogFragmentTest$FragmentUtilActivity } -- see https://github.com/robolectric/robolectric/pull/4736 for details
java.lang.RuntimeException:
at org.robolectric.android.fakes.RoboMonitoringInstrumentation.startActivitySyncInternal(RoboMonitoringInstrumentation.java:48)
at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:34)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:205)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:182)
at androidx.test.ext.junit.rules.ActivityScenarioRule.lambda$new$0(ActivityScenarioRule.java:68)
at androidx.test.ext.junit.rules.ActivityScenarioRule.before(ActivityScenarioRule.java:82)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:546)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:252)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)