Nimble icon indicating copy to clipboard operation
Nimble copied to clipboard

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

Open Bogdan-Belogurov opened this issue 2 years ago • 6 comments

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:

  • Quick: 13.0.0
  • Nimble: 7.3.0
  • Xcode Version: 14.3 (14E222b)
  • Swift Version: 5.8

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

  • Tuist 3.28.0

Project that demonstrates the issue

QuickProject.zip

To run the project:

  1. make tooling
  2. make project
  3. Run QuickProjectKitTests

Bogdan-Belogurov avatar Nov 21 '23 11:11 Bogdan-Belogurov

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.

younata avatar Nov 23 '23 18:11 younata

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

Bogdan-Belogurov avatar Nov 30 '23 13:11 Bogdan-Belogurov

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

Bogdan-Belogurov avatar Nov 30 '23 13:11 Bogdan-Belogurov

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.

mokagio avatar Dec 08 '23 08:12 mokagio

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.

younata avatar Dec 08 '23 19:12 younata

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

Narsail avatar Jun 04 '24 13:06 Narsail