Integrate logging system into Flutter app with service registration and testing setup
This commit is contained in:
69
finlog_app/fluttery/test/logger/logger_test.dart
Normal file
69
finlog_app/fluttery/test/logger/logger_test.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:logging/logging.dart' as lib;
|
||||
import 'package:fluttery/src/logger/logger_impl.dart';
|
||||
|
||||
// Mock class for the lib.Logger
|
||||
class MockLibLogger extends Mock implements lib.Logger {}
|
||||
|
||||
void main() {
|
||||
final mockLibLogger = MockLibLogger();
|
||||
|
||||
group('LoggerImpl', () {
|
||||
late LoggerImpl loggerImpl;
|
||||
|
||||
setUp(() {
|
||||
loggerImpl = LoggerImpl.forTest(mockLibLogger);
|
||||
});
|
||||
|
||||
test('info method logs an info message', () {
|
||||
loggerImpl.info('Info message');
|
||||
|
||||
// Verify that the info method was called on the mock logger with the correct message
|
||||
verify(() => mockLibLogger.info('Info message')).called(1);
|
||||
});
|
||||
|
||||
test('warning method logs a warning message', () {
|
||||
loggerImpl.warning('Warning message');
|
||||
|
||||
// Verify that the warning method was called on the mock logger with the correct message
|
||||
verify(() => mockLibLogger.warning('Warning message')).called(1);
|
||||
});
|
||||
|
||||
test('error method logs an error message with optional parameters', () {
|
||||
final exception = Exception('Test exception');
|
||||
final stackTrace = StackTrace.current;
|
||||
|
||||
loggerImpl.error('Error message', exception, stackTrace);
|
||||
|
||||
// Verify that the severe method was called on the mock logger with the correct parameters
|
||||
verify(
|
||||
() => mockLibLogger.severe('Error message', exception, stackTrace),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('debug method logs a debug message', () {
|
||||
loggerImpl.debug('Debug message');
|
||||
|
||||
// Verify that the fine method was called on the mock logger with the correct message
|
||||
verify(() => mockLibLogger.fine('Debug message')).called(1);
|
||||
});
|
||||
|
||||
test('setLogLevel method sets the logger level', () {
|
||||
// This is to capture the change in the logger level
|
||||
var capturedLevel = lib.Level.INFO;
|
||||
|
||||
// Capture the setter call
|
||||
when(() => mockLibLogger.level = any()).thenAnswer((invocation) {
|
||||
capturedLevel = invocation.positionalArguments.first as lib.Level;
|
||||
return capturedLevel;
|
||||
});
|
||||
|
||||
// Set the log level
|
||||
loggerImpl.setLogLevel(lib.Level.WARNING);
|
||||
|
||||
// Verify that the logger level is set to the expected level
|
||||
expect(capturedLevel, lib.Level.WARNING);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user