1

Is there a way to write unit tests for Sentry in Flutter?

I have a function that takes in a set of inputs and reports to Sentry

reportError({...}){
  Sentry.captureException(stackTrace, stackTrace: stackTrace, hint: hint);
}

And I want to write a unit test for the same

  test('sends to sentry', () {
      reportError(
        hint: 'error',
        response: Response(
          json.encode(<String, dynamic>{'message': '4: error'}),
          401,
        ),
      );
    });

The question is, how do I verify that the error was logged?

1 Answer 1

1

You can set a custom mock client in tests using Sentry.bindClient() - see how Sentry does it in its unit tests here: https://github.com/getsentry/sentry-dart/blob/02419b742e39fd070faa613151db22e5b8c9f041/dart/test/sentry_test.dart

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.