how to write unit test with firebase crashlytics in catch method in flutter

Viewed 21

How to write unit test for this code.

class CommonUtils
{
  static String getDisplayFormat(String dateTime) {
    try {
      if (dateTime.contains('T')) {
        DateTime formattedTime =
        DateFormat(TStrings.mxDateTimeFormat).parse(dateTime);
        return DateFormat('dd/MM/yy hh:mm a').format(formattedTime);
      } else {
        DateTime formattedTime =
        DateFormat(TStrings.dateTimeFormat).parse(dateTime);
        return DateFormat('dd/MM/yy hh:mm a').format(formattedTime);
      }
    } catch (exception, stacktrace) {
      FirebaseCrashlytics.instance.log("While calling getDisplayFormat ");
      FirebaseCrashlytics.instance.recordError(exception, stacktrace);
      return "";
    }
  }
}

Without using firebase in catch method, I can able to write test, but with firebase in crashlytics how to write unit test?

0 Answers
Related