gpt4 book ai didi

java - 如何在同一 Activity 中同步运行 Espresso 测试套件测试类?

转载 作者:行者123 更新时间:2023-12-01 22:27:15 25 4
gpt4 key购买 nike

我想同步运行一组测试。理想情况下,我希望将这些测试集模块化为单独的类,因为将它们合并为 1 个类将导致文件太大。例如,我有以下测试套件文件:

@RunWith(Suite.class)
@Suite.SuiteClasses({
LoginTest.class,
AddItemsTest.class,
ItemTest.class,
ArchiveTest.class,
LogoutTest.class
})
public class FullTest{}

这些测试用例按顺序运行,但是我对继续在这些测试用例之间使用相同的上下文和 Activity 感到困惑。我在运行测试时遇到错误,没有找到 Activity ...

E/TestRunner: failed: runAddItems(com.XXX.XXX.functional.TestSuite.AddItemsTest)
----- begin exception -----
E/TestRunner: java.lang.RuntimeException: No activities found. Did you forget to launch the activity by calling getActivity() or startActivitySync or similar?
at androidx.test.espresso.base.RootViewPicker.waitForAtLeastOneActivityToBeResumed(RootViewPicker.java:176)
at androidx.test.espresso.base.RootViewPicker.get(RootViewPicker.java:88)
at androidx.test.espresso.ViewInteractionModule.provideRootView(ViewInteractionModule.java:77)
at androidx.test.espresso.ViewInteractionModule_ProvideRootViewFactory.provideRootView(ViewInteractionModule_ProvideRootViewFactory.java:37)
at androidx.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:27)
at androidx.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:10)
at androidx.test.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:63)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:280)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:272)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6949)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
----- end exception -----

我需要做什么特定的事情才能继续我在上一个测试用例中停止的工作流程?

最佳答案

我认为这不是一个有效的解决方案,但我想通了。我只是创建一个单独的 Test 类,并在我的测试中创建它的一个实例。这有效。

关于java - 如何在同一 Activity 中同步运行 Espresso 测试套件测试类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58563573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com