不良状态:一旦测试开始运行就无法调用 test()

问题描述 投票:0回答:2

我在运行 flutter bloc 测试期间遇到问题。初始测试用例运行成功,但块测试给出了此异常。 这是我的测试代码:

import 'package:bloc_test/bloc_test.dart';
import'package:dictionary_bloc/features/dictionary_search/data/data_source/dictionary_fnx.dart';
import'package:dictionary_bloc/features/dictionary_search/presentation/bloc/dictionary_cubit.dart';
import'package:flutter_test/flutter_test.dart';

void main(){
  group("cubit testing", () {

    late DictionaryCubit dictionaryCubit;

    setUp((){
      dictionaryCubit = DictionaryCubit(DictionaryFnx());
    });

    test("Initial test", () {
      expect(dictionaryCubit.state, NoWordSearchedState());
    });


    group("word search group", () {
      test("number searching", (){
        blocTest<DictionaryCubit,DictionaryState>("word search not successful",
            build: ()=> dictionaryCubit,
            act: (cubit) async => await cubit.getWordSearched("1"),
            expect: ()=> <DictionaryState>[ErrorState("No WordFound")]
        );
      });
    });
  });
}
flutter testing bloc flutter-bloc
2个回答
1
投票

blocTest
中取出您的
test()
blocTest
已经是一个测试


0
投票

您不能在 blocTest 内调用 test,因为 blocTest 本身就是一个测试函数。相反,您应该直接使用 blocTest 进行测试。

© www.soinside.com 2019 - 2024. All rights reserved.