umair13adil / flutter_logs

An extensive logging framework developed for flutter apps.
https://itnext.io/sending-logs-from-flutter-apps-in-real-time-using-elk-stack-mqtt-c24fa0cb9802
Apache License 2.0
40 stars 32 forks source link

Usage with tests / mock? #54

Closed Myzel394 closed 1 year ago

Myzel394 commented 1 year ago

Is there some way to use this with unit tests / mock the functions?

Myzel394 commented 1 year ago

Okay seems like this project is dead basically. Anyway, if you still want to use it, here's how I fixed it:

  1. You need to use testWidgets instead of test
  2. You need to mock the method handler (see code below)

Example:

    testWidgets("my test", (tester) async {
      tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
        const MethodChannel("flutter_logs"),
            (call) async {
          if (call.method == "logThis") {
            print(
              "{${call.arguments['tag']}}  {${call.arguments['subTag']}}  {${call.arguments['logMessage']}}  {${DateTime.now().toIso8601String()}  {${call.arguments['level']}}",
            );
          }

          return "";
        },
      );
    });