Unit testing 有没有办法在颤振单元测试中测试AppLifecycleState变化?
当我的应用移动到后台(AppLifecycleState.paused)时,我的应用会将用户首选项写入本地文件,我想为此行为编写一个测试Unit testing 有没有办法在颤振单元测试中测试AppLifecycleState变化?,unit-testing,flutter,Unit Testing,Flutter,当我的应用移动到后台(AppLifecycleState.paused)时,我的应用会将用户首选项写入本地文件,我想为此行为编写一个测试 有没有办法在单元测试中模拟这种情况?或者这是需要作为集成测试来完成的吗?您可以调用绑定。handleAppLifecycleStateChanged在单元测试中模拟应用程序进出前台。您可以调用绑定。handleAppLifecycleStateChanged在单元测试中模拟应用程序进出前台测试。测试仪。binding.handleAppLifecycleSta
有没有办法在单元测试中模拟这种情况?或者这是需要作为集成测试来完成的吗?您可以调用
绑定。handleAppLifecycleStateChanged
在单元测试中模拟应用程序进出前台。您可以调用绑定。handleAppLifecycleStateChanged
在单元测试中模拟应用程序进出前台测试。测试仪。binding.handleAppLifecycleStateChanged绝对是测试它的正确方法
例如:主页上的Statefull小部件,用于侦听应用程序生命周期
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
pushLoginPage(context);
}
}
如果要测试此功能,必须先暂停
,然后恢复,以确保颤振导航。tester.binding.handleAppLifecycleStateChanged
绝对是测试此功能的正确方法
例如:主页上的Statefull小部件,用于侦听应用程序生命周期
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
pushLoginPage(context);
}
}
如果你想测试这个,你必须先暂停,然后继续,以确保颤振导航