Quick / Nimble

A Matcher Framework for Swift and Objective-C
https://quick.github.io/Nimble/documentation/nimble/
Apache License 2.0
4.79k stars 595 forks source link

Attempted to report a test failure to XCTest while no test case was running #1101

Open Bogdan-Belogurov opened 7 months ago

Bogdan-Belogurov commented 7 months ago

What did you do?

Upgraded the Nimble to 13.0.0 from 9.2.0 and Quick to 7.3.0 from 4.0.0 to use AsyncSpec

What did you expect to happen?

AsyncSpec should notify about errors like regular QuickSpec.

What actually happened instead?

When I moved some tests to AsyncSpec.
and received: Attempted to report a test failure to XCTest while no test case was running. error. Maybe you know how I can avoid this bug?

image

Environment

List the software versions you're using:

Please also mention which package manager you used and its version. Delete the other package managers in this list:

Project that demonstrates the issue

QuickProject.zip

To run the project:

  1. make tooling
  2. make project
  3. Run QuickProjectKitTests
younata commented 7 months ago

What's the rest of the error? The message between the "Attempted to report a test failure to XCTest while no test case was running. The failure was:" and "It occurred at: [...]" lines. That'll help with determining what the actual issue is.

Bogdan-Belogurov commented 7 months ago

Yes, you are right that's how I live now, but it's very difficult compared to the previous behavior.

Bogdan-Belogurov commented 7 months ago

I uploaded a test project with the issue, please take a look.

mokagio commented 7 months ago

I haven't looked at @Bogdan-Belogurov's example project, but I just got this unexpected behavior as well. Interestingly, I am also using Tuist.

younata commented 7 months ago

This is caused by Nimble's CurrentTestCaseTracker.sharedInstance() not getting registered with XCTest. In particular, XCTestObservationCenter+Register.load's override isn't getting called.

Which appears to be caused by Tuist improperly handling Nimble's Package.swift (specifically, it looks like they're not including the NimbleObjectiveC stuff specified in our Package.swift). Until Tuist fixes this, I'd suggest following Tuist's documentation for using the native SPM integration.

I filed an issue with Tuist to hopefully get it resolved at some point.

Narsail commented 1 month ago

Alternatively what helped me was to make Nimble and its dependencies dynamic:

#if TUIST
    import ProjectDescription

    let packageSettings = PackageSettings(
        productTypes: [
            "Nimble": .framework,
            "CwlPreconditionTesting": .framework,
            "CwlPosixPreconditionTesting": .framework,
            "CwlCatchException": .framework,
            "NimbleObjectiveC": .framework,
            "CwlMachBadInstructionHandler": .framework
        ]
    )
#endif