如何在用例中模拟 void 参数

How to mock void parameter in use case

提问人:Nikita Shadkov 提问时间:8/16/2023 更新时间:8/16/2023 访问量:25

问:

我确实有下一个用例

class GetLessonsUseCase extends UseCase<List<LessonEntity>, void> {
  final LessonsRepository _repository;

  GetLessonsUseCase(this._repository);

  @override
  Future<List<LessonEntity>> call({void params}) async {
    return _repository.getLessons();
  }
}

问题是 Mockito 生成了下一个带有错误的代码

// A class which mocks [GetLessonsUseCase].
///
/// See the documentation for Mockito's code generation for more information.
class MockGetLessonsUseCase extends _i1.Mock implements _i9.GetLessonsUseCase {
  @override
  _i3.Future<List<_i4.LessonEntity>> call({void params}) => (super.noSuchMethod(
        Invocation.method(
          #call,
          [],
          {#params: params},
        ),
        returnValue: Future<List<_i4.LessonEntity>>.value(<_i4.LessonEntity>[]),
      ) as _i3.Future<List<_i4.LessonEntity>>);
}

generated error

我试图用 声明它,但仍然不起作用returnNullOrMissing

@GenerateMocks([
  LessonsRepository,
  // GetLessonsUseCase,
  SetDrawerBadgesUseCase,
  GetYoutubeIconUseCase,
], customMocks: [
  MockSpec<GetLessonsUseCase>(returnNullOnMissingStub: true),
])
Flutter Dart 单元测试 mockito 用例

评论


答: 暂无答案