(6) initial unit test experience

Source: Internet
Author: User

It has been working on i6p or I6 products and framework maintenance for three years in xinzhong University. Although I have heard of unit tests before, I have a basic idea of testing in my concepts! In addition, xinzhongda focuses on product development. To run the logic, you must overwrite the DLL to the product. There is no concept of unit testing at all. So when the boss of skey networks asked me to perform unit tests on iOS, I was quite disgusted and had the following questions:

Why test? If you want to test your own button and run the code, isn't that all right? What unit tests do I have to write? Isn't that a half-done? Multiple times?

However, after I used a unit test, I realized it. In the original unit test, you can complete your own independent test code without writing buttons. Does this sound attractive? I understand this truth only after careful consideration. In fact, you have to drag a button on the interface for all the things you have tested before, click it, and get the data for testing. After the test is complete, comment out the useless code. In this way, you will find that you are so second! These things have long been implemented by great engineers and designers for you. You only need to re-write an independent code that can be fully independent from the main product to complete your tests without deleting any code.

Someone may ask, "What is an independent code ?". In fact, the answer is very simple: an algorithm, a function, a class... All calculations, as long as the code you write can be called by the client, and it is independent and complex. It's too simple to write. During testing, you only need to simulate the data that may be called elsewhere. The xcode compiler will help you output the desired results. Errors will prompt you .....

Here is a simple description:

-(Void) testexample

{

Nsstring * [email protected] "http: // % @/FM/querymode ";

Skyquerymodelrequest * request = [[skyquerymodelrequest alloc] init];

[Email protected] "mopote_12000001 ";

 

[Email protected] "20140815073320 ";

Request. provcie = 33;

Request. City = 571;

Request. Operators = 0;

Nsstring * [email protected] "i3yy5cpe8sn0 ";

Request. privatekey = [skysignutils signwithpdcode: request. productcode withpwd: Pwd withmobile: request. telphonenumber clienttime: request. datetime];

 

Skyquerymodelresponse * response = [skycodecfactory requestwithurl: URL withobject: Request withresultname: @ "skyquerymodelresponse"];

Nslog (@ "% d", response. bussinessid );

}

 

You can write the above method in the unit test class. The method name must start with test. Click the method name to fully simulate the click operation on the interface ..... Wow, although it is very simple, it was a little excited when I used it for the first time. As a small skill!

(6) initial unit test experience

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.