Skip to content

Testing using loggingService? #164

Open
@dnfield

Description

@dnfield

Is there a good way to mock or stub the loggingService when writing unit tests? Or perhaps overriding the service scope resolution?

Basically I'd like to test a method that ends up calling loggingService.xxx in some cases, and right now when I hit those branches I get output like the following:

Bad state: Not running inside a service scope zone.
package:gcloud/service_scope.dart 140:5                      lookup
package:appengine/src/logging.dart 67:31                     loggingService
package:cocoon_service/github.dart 21:5                      getPullRequest
===== asynchronous gap ===========================
dart:async                                                   _AsyncAwaitCompleter.completeError
package:cocoon_service/github.dart                           getPullRequest
===== asynchronous gap ===========================
dart:async                                                   _asyncThenWrapperHelper
package:cocoon_service/request_handlers/github_webhook.dart  githubWebhookPullRequest
test/request_handlers/github_webhook_test.dart 77:13         main.<fn>.<fn>
No matching calls (actually, no calls at all).
(If you called `verify(...).called(0);`, please instead use `verifyNever(...);`.)
package:test_api                                      fail
package:mockito/src/mock.dart 641:7                   _VerifyCall._checkWith
package:mockito/src/mock.dart 834:18                  _makeVerify.<fn>
test/request_handlers/github_webhook_test.dart 39:13  main.<fn>.<fn>
✖ githubWebhookPullRequest Rejects non-json
Exited (1)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions