fake_firebase_ai 0.1.0
fake_firebase_ai: ^0.1.0 copied to clipboard
Fake for Firebase AI Logic (firebase_ai). Unit test Gemini calls, streaming, chat and function calling without network or API keys.
example/fake_firebase_ai_example.dart
import 'package:fake_firebase_ai/fake_firebase_ai.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'package:flutter_test/flutter_test.dart';
/// The code under test: takes a model, so tests can pass a fake one.
Future<String> summarize(GenerativeModel model, String article) async {
final response = await model.generateContent([
Content.text('Summarize in one line:\n$article'),
]);
return response.text ?? '';
}
void main() {
test('summarize sends the article and returns the reply', () async {
final ai = FakeFirebaseAI()..reply('Cats are great.');
final model = await ai.generativeModel('gemini-2.5-flash');
expect(
await summarize(model, 'A long article about cats.'),
'Cats are great.',
);
expect(ai.requests.single.text, contains('about cats'));
});
}