[Pitch] Prettify XCTAssertEqual

As developer, Unit Test is part of our daily life. With it, we can assure the stability of our code.
XCTest is framework to write unit tests on swift, and i believe XCTAssertEqual is one if not the most used assert.

but current output for the assertion is like this

Several issue with current output

  • it's hard to find which property or variable that cause the error
  • if the object that being assert have huge property, much harder to check

inspired by swift-composable-architecture#Diff.swift diff function (used for creating better output for state changes), we can create better XCTAssertEqual output to highlight the issue.

Screen Shot 2021-06-11 at 09.48.04

Let me know what do you think about this idea

19 Likes

+1
I would really love this to be native to XCTest

2 Likes

This would be great, as would many other changes and improvements to XCTest and testing in Swift generally. However, XCTest, like Foundation, is not subject to the Swift Evolution process, given its closed-source nature on Apple platforms, so it's unlikely we can do much to help here.

3 Likes

what would you suggest, should we open feedbacks instead?

isnt XCTest an open source project here GitHub - apple/swift-corelibs-xctest: The XCTest Project, A Swift core library for providing unit test support ?

Yes.

That, like swift-corelibs-foundation, is an open, Swift-native port of the framework for non-Apple platforms. Since the APIs of the framework must maintain parity with the Apple version, we can't add APIs or other behavior changes in the open version by itself. Apple drives the evolution of these APIs.

4 Likes

FYI. Also MirrorDiffKit can do show readable messages. Notably, MirrorDiffKit also can show readable messsages for Sequences. For example:

[
    child: "I'm not changed"
    sequences: [
      - "I'm deleted"
      + "I'm inserted"
        "I'm not changed"
    ]
]

See tests to see more examples.

1 Like

There may be hope that changes will be accepted even if they are not part of swift evolution. Recently a small change to the signature of XCTAssertThrowsError was proposed here and the PR was indeed merged: Change XCTAssertThrowsError function signature to rethrow when the error handler throws

1 Like

For what it's worth, we just extracted the diff/dump logic from the Composable Architecture into its own repo: GitHub - pointfreeco/swift-custom-dump: A collection of tools for debugging, diffing, and testing your

It comes with an XCTAssertNoDifference helper, which can be a drop-in replacement for XCTAssertEqual.

14 Likes
Terms of Service

Privacy Policy

Cookie Policy