Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

xcode - What are the limitations of an iOS hostless test target (formerly logic tests)?

TLDR: What are the limitations of running iOS unit tests without a host application?


It seems a lot of posts on the internet regarding iOS hostless tests (Logic vs Application Tests) may be out of date. For example, according to this and this Stack Overflow post you cannot instantiate a UIFont in logic tests. I just tried to do so with Xcode 8.2.1 and iPhone 7 simulator running iOS 10.2 and it seems to work fine.

Here is an example project with such a test: https://github.com/lyahdav/SnapshotLogicTest

According to this blog post:

This is actually a limitation of Xcode logic tests—they don't fire up a UIApplication instance and don't play nicely with UIKit

But if you look at my example project above it's creating a UIView and using FBSnapshotTestCase to assert views are rendered the same in a logic test and everything seems to work fine.

Also I can't find Apple's documentation for Logic vs Application tests anymore. For example, this post and this post link to Apple web pages which seems to be dead now and I can't find a newer page that replace it.

I wonder if Apple has minimized the distinction since the difference is simply setting a host application on your test target or not. But it's not clear to me if there are any limitations with Logic Tests. I really like them because it allows me to create smaller, more isolated test targets for parts of my app that can run much faster that an Application Test suite.

UPDATE: I figured I'd add a note about UI Testing. Per that Apple doc, starting in Xcode 7 they added UI Testing as part of XCTest. This seems to be orthogonal to the point about a host vs hostless unit test target.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I wonder if Apple has minimized the distinction since the difference is simply setting a host application on your test target or not.

There are now Unit Tests and UI Tests. Both involve running the application. Apple no longer talks about logic tests separately at all.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...