Nei*_*ard 1 mockito dart flutter-test
我有这个方法:
\n\nFuture<Either<Failure, WorkEntity>> updateWorkEntity({int id, String title, TimeType timeType, int times, DateTime executed})\nRun Code Online (Sandbox Code Playgroud)\n\n被这样称呼:
\n\nrepository.updateWorkEntity(id: workEntity.id, executed: DateTime.now())\nRun Code Online (Sandbox Code Playgroud)\n\n我可以在测试中控制 id,但我当然不能控制“DateTime.now()”。我在测试中尝试的是这样的:
\n\nwhen(repository.updateWorkEntity(id: expected.id, executed: any)).thenAnswer((_) async => Right(expected));\nRun Code Online (Sandbox Code Playgroud)\n\n通过使用“any”代替“DateTime.now()”,能够使我的模拟返回一个对象进行测试,但我收到此错误:
\n\n\n\n\n\n
when无效参数:“任何”参数匹配器在方法存根(通过)或验证(通过verifyor\n )之外使用untilCalled。这是无效的,并且会在下一次存根或验证期间导致不良行为。
所以我想我不能在这里使用任何参数,但是当我不控制输入参数之一时,如何让我的模拟返回一个对象呢?
\n\n谢谢
\nS\xc3\xb8ren
| 归档时间: |
|
| 查看次数: |
2086 次 |
| 最近记录: |