1. Like the steps to create a project in general. Create a project for testing or open a test item.
(OC is a test that was used before 5.0, and now uses xctestcase, which creates a primary test class by default.) Once version number may be very many steps omitted)
For example: we can see a test file in text, and now all test classes inherit the Xctestcase class.
2, write the corresponding test example in the test class, test class to test the class needs to enter the corresponding class header file, this is rightfully. Then perform the "Perform test". Shortcut keys: command+u or product-> test.
The following is a document after successful execution.
The above is a simple example of a successful test.
2, the difference between the different version number:
People who are familiar with ocutest should be able to be familiar with ocunit very quickly. Since it is generally the same, xctest is a further encapsulation of the ocunit.
There is a slight difference in the following point:
1) using different frameworks, test cases need to inherit different base classes, xctest inherit Xctestcase base class, and Ocunit inherit Sentest base class.
2) because the inherited base classes are different, the prefixes of the method names that are asserted will also change. The assertion method in Xctest is xct--, which is the first few letters. The same ocuint is St. is the prefix of the sentest.
3) (maximum difference) in Xctest, use the class method. Users are able to use the class method's level of Setup and Teardown methods. Make the test code more reasonable.
More effective control of the test method between the isolation environment problem. We
4) After 6.0, the class method is omitted, which is directly the setup (entry) and teardown (out) method of the instance and the corresponding instance method.
Exceptions two methods we can see from the English, one is the test function of the sample, one is the test performance of the sample.
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "height=" 362 "width=" 719 ">
The ability to look at the red places above adds a way to detect code performance.
3. Today's Xcode is able to "split the logic test" through a manageable number of test examples. There are very many differences in the growth and evolution of the codebase.
Ocunit and Xctest compatibility, the conversion between them is based on the target-->by--> target
Steps:
1. Select Edit > Refactor > Convert ocunit to Xctest.
2. Click Next to go to the next worksheet.
3. In the form that appears, select the test target that you want to convert.
4. To see if a specific target can be converted to xctest. Please click its name.
5. Click Next button. A filemerge interface pops up to check for changes. (This step is the way we often use to give edge file name Word)
6. If you are sure that this is the change, you can click save button. Xcode will write the changes to the file.
See Links:
Http://www.cocoachina.com/ios/20140717/9168.html
4, writing test is to pay attention to some details:
1) Test example of the method should be the prefix test, we often write as disable_test ... This will not be tested, because recognition is only the beginning of the recognition test.
2) test requires a position to be placed. For example, when we test a use case, we can create the corresponding class and inherit the Xctestcase. It's good to choose to create a test class directly in Xcode.
3) test to have a certain tone effect, the expression of the expected effect in iOS is generally expressed using assertions.
4) The Xctestcase test is measured according to a row, assuming failure, the assertion throws an exception.
5) Test examples, test examples (can only have one method, or multiple methods), run the sequential setup--> test example of the method--teardown.
iOS unit test Ocunit and updated xctestcase