XCTest Helper Methods

XCTest Helper Methods

This is for anyone writing unit tests in Xcode.

If you are writing a helper method that gets called from numerous tests using the XCTest framework, you may have noticed that if something fails and the code is within your helper method, you will just see a failure in the helper method and not any information about which line in which test it failed. 

Here is an example of what I mean from my open source project: Music Notation Kit.

Well, I figured out a pretty useful, easy solution. I thought about how asserts were implemented and borrowed from that. All you have to do, is add some parameters for the function name and line number that have default values, which get evaluated where they are called. Here is the outcome:

And now you have useful errors in helper methods! Check out the commit that fixed this issue here.

Let me know if you have any comments or question about my approach.

Alia Sayegh

AUTHOR at Writer @ Large

9 年

congrats

回复

Super useful! Thanks for sharing

要查看或添加评论,请登录

Kyle Sherman的更多文章

社区洞察

其他会员也浏览了