Skip to content

Unit tests: Global reference to userID across multiple Analytics instances #1066

@cprince-foreflight

Description

@cprince-foreflight

I have some unit tests that use Analytics to carryout some testing. Some of these create the Analytics objects in static members. i.e., so the Analytics object is effectively global, scoped to those test cases. This has worked well so far, but I'm running into an issue.

In a new test, I wanted to get a new instance of Analytics and I assumed the userId would be nil. That's part of what I'm testing. Since, in that XCTestCase class hadn't initialized it. i.e., I hadn't done an identify call. However, the other XCTestCases test do those identify calls, and happen to get initialized first across all the test targets of my Swift package.

It looks like Analytics shares a global value for userId across Analytics instances. This is making my testing a bit tricker than I would have expected. Not sure if this is operating as expected or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions