我尝试在Flutter中使用Supabase进行单元测试,如以下代码:
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
class TestMClass {
SupabaseClient client;
TestMClass({
required this.client,
});
Future<AuthResponse> signinMc() async {
final respnse = await client.auth
.signInWithPassword(email: 'example@gmail', password: 'password');
return respnse;
}
}
class MockSupabaseClient extends Mock implements SupabaseClient {}
void main() async {
final MockSupabaseClient mockClient = MockSupabaseClient();
final TestMClass testMCass = TestMClass(client: mockClient);
setUp(() {});
group('TestAuthBloc', () {
test('description', () async {
final auth = await testMCass.signinMc();
expect(auth, isA<AuthResponse>());
});
});
}
它抛出此错误:....
类型“Null”不是类型“GoTrueClient”的子类型
我如何用Flutter模拟或做Supabase函数的单元测试?
1条答案
按热度按时间7kjnsjlb1#
你可以像这样使用Fake类: