Recently, younger brother in his own study of Swift, accustomed to writing while writing unit tests while writing logic, in the Xcode environment without unit testing, writing is not a real feeling.
As to how to create unit test, how to write, not the subject of this article, because read a lot of Baidu to the swift unit test, has been very graphic introduction to tell you how to write unit test. But the big question is, whether you call the class in your project anyway in the test class and say it's undefined, how does this happen? Fqgoogle a hand. Finally understand.
First of all, your project and test project is separate 2 target, if you need to call in the unit test project in the project of the class, you must go to the unit test the class and the class dependence class, choose this diagram:
Then you can refer to it in the test method.
Another option is to use the keyword public, the public of the class being tested, and the method to be tested public, so that the import of your project name in the test project can be called, but this method has some drawbacks, that is, public will limit the return type is not allowed, Just to be blunt, these types can not be translated, and there is no need for each clsss and func public, personal advice or plan I.
No technical content of the article, purely remark.
Finally the sentence: Baidu harm, less use once is, Google you will come back?
Supplement to Swift Unit testing