0
import 'package:flutter_bloc_master/core/common/entities/user.dart';
import 'package:flutter_bloc_master/core/error/failures.dart';
import 'package:flutter_bloc_master/features/auth/domain/repository/auth_repository.dart';
import 'package:flutter_bloc_master/features/auth/domain/usecases/user_login.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fpdart/fpdart.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';

import 'user_login_usecase_test.mocks.dart';

@GenerateMocks([AuthRepository])
void main() {
  late MockAuthRepository mockAuthRepository;
  late UserLogin userLogin;

  setUp(() {
    mockAuthRepository = MockAuthRepository();
    userLogin = UserLogin(mockAuthRepository);
  });

  const tEmail = '[email protected]';
  const tPassword = '12345678';
  const user = User(id: '', email: tEmail, name: 'dinod tharinda');

  test('User login', () async {
    //arrange
    when(mockAuthRepository.loginWithEmailPassword(
            email: tEmail, password: tPassword))
        .thenAnswer((_) async => const Right(user));

    final result = await userLogin(
      UserLoginParams(email: tEmail, password: tPassword),
    );

    result.fold((l) {
      expect(l, isA<Failure>());
    }, (r) {
      expect(r, isA<User>());
    });
  });
}

Flutter mockito unit test not working. I used clean architecture for this project with blocs. Database is supabase

not working unit test. below I mention console log. when I use mockail comes different error.

console log

MissingDummyValueError: Either<Failure, User>

This means Mockito was not smart enough to generate a dummy value of type 'Either<Failure, User>'. Please consider using either 'provideDummy' or 'provideDummyBuilder' functions to give Mockito a proper dummy value.

Please note that due to implementation details Mockito sometimes needs users to provide dummy values for some types, even if they plan to explicitly stub all the called methods.

package:mockito/src/dummies.dart 156:3 dummyValue test\user_login_usecase_test.mocks.dart 83:17 MockAuthRepository.loginWithEmailPassword test\user_login_usecase_test.dart 28:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.