import 'package:flutter_test/flutter_test.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path_provider/path_provider.dart'; import 'db_helper.dart'; import 'product.dart'; void main() { group('Product Tests', () { late Database db; setUp(() async { final io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); String path = '${documentsDirectory.path}/test.db'; db = await openDatabase(path, version: 1, onCreate: DbHelper()._onCreate); }); tearDown(() async { await db.close(); final io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); String path = '${documentsDirectory.path}/test.db'; await io.File(path).delete(); }); test('Add and fetch product', () async { final product = Product( name: 'Test Product', unitPrice: 100.0, discount: 0.1, ); await db.insert('products', product.toMap()); final List> maps = await db.query('products'); expect(maps.length, 1); final fetchedProduct = Product.fromMap(maps.first); expect(fetchedProduct.name, 'Test Product'); }); }); }