samedi 30 juillet 2016

How can I write automated tests for custom XCTest assertions?

I am developing a testing framework for iOS development. I'd also like for this testing framework to be well-tested. The problem is, I can't figure out how to write a test for my test target that asserts my framework is correctly causing failed tests. If I create a failed test, I have in turn, caused the test to fail (I know, it's confusing).

Consider an example. Part of my framework includes function to verify that a particular code snippet does not have any breaking constraints.

MTKAssertNoBrokenConstraints {
    // UI code that might break some constraints
}

I have tested this by hand to verify that when there are no broken constraints, the assertion passes, but when there are broken constraints, it correctly marks the test as failing.

But I need a way to verify that MTKAssertNoBrokenConstraints would mark a test as failing without actually marking the test for this itself as failing.

I have looked into creating a custom object that conforms to XCTestObservation, but so far I've only ended up with infinite recursion. I'm not sure whether this is the right path, or whether resolving the infinite recursion will actually get me where I need to be.

Aucun commentaire:

Enregistrer un commentaire