开发者

Ways of running quick and dirty tests in XCode4

I'm trying to figure out how to run a quick and dirty test time efficiently.

Sometimes I run into a situation where I want to test a few lines of code. For example, test whether NSMutableDictionary crashes if I initWithDictionary but use nil.

Right now I create a new project and test it out. I've also been known to just add the simple test into the main delegate (so it's开发者_JAVA技巧 the first thing loaded.)

Creating a project takes too much time and space, and editing delegate has potential of causing other problem (forgot to remove, etc), plus it requires recompiling.

Are there better alternatives to these two methods? Something like: evaluate expression, or evaluate two lines of expression.


I know Dave DeLong keeps a throwaway project around specifically for things like this. Just make a new project and call it "Nothing" or something. Rather than throwing it away when you're done, just save the project. Next time you need to test some code, just open up the Nothing project and drop your code in.

Of course, this works best if you're just testing the behavior of Apple frameworks. If you need to link against your own code, a unit test target would probably be better.


The best way would be to add a unit tests target to your project and create unit test cases for the code you'd like to try out.

They can even stay there in case of refactoring in project's future.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜