This article reprinted to http://blog.csdn.net/fengsh998/article/details/8109293IOS comes with unit tests.
1. When created, include the Unit tests hook.
This creates a test project that automatically generates a tests knot. Open PROJECTTEST.M to see a test method that the system has created good one test examples testexample
You can now run the test unit to see the effect.
Click Run, press and hold the pop-up test, select test
The running result is of course a test method, because there is a self-contained demo code.
Here, the test unit project is ready to work.
Write a test method below to try it out.
The newly created test class must be sentestcase as the base class.
The test method name must be prefixed with test.
-(void) Testisok
{
NSLog (@ "Call here");
}
Refer to the. h text when testing a class method in a test project. You can test the corresponding method by creating the corresponding instance object.
2, in the existing projects to create test engineering.
Click File--new--new Target
In the pop-up selection box Ios-->other---> Cocoa Touch Unit testing Bundle
Click Next to enter the project name.
Click Done.
A test project will be generated.
It seems ok here, but still a step, after clicking on Run, the long press to produce test, click Test to open the test, will produce a hint: the scheme "project name" is not a configured for testing. Edit the scheme to enable Testing,or cancel the action.
That is, we have not yet configured a test project line for the project, click Edit to add it, or click Cancel to finish.
Click on Edit scheme (or Producu->edit scheme in the menu)
Pop up the scheme form. Check test and click on the + sign to add a scheme
Select the previously created Coredatademotest and click Add
Add post effect.
Click OK to run the test project.
The run section is shown in the previous Run Test Unit section.
To this, iOS comes with a test unit complete, for third-party ghunit and Ocmock see:
Articles in the http://www.uml.org.cn/mobiledev/201201093.asp
IOS Unit Test