Understanding of the iOS test framework

Source: Internet
Author: User

Testing for iOS

Cedar, Specta, Kiwi, xctest
The difference between specta and Kiwi is that Kiwi contains all the functions of specta and Ocmock and Expeata.

The role of the test framework:
Because of the progress in the industry, we usually do not use TDD to test, but with BDD to test.
BDD is an important part of "data access" for testing.

"Terminology" understands:
BDD (Behavior Driven development), or behavior-driven development, is designed to solve specific problems and help developers determine what should be tested.
TDD (Test-driven development) is a test-driven development that drives the entire development through testing.

Gihub The above frame:
The test framework above the OC language:
Wiki Https://github.com/kiwi-bdd/Kiwi/wiki
Specta Https://github.com/specta/specta
Cedar Https://github.com/pivotal/cedar
Xctest and Xcode are highly integrated

Testing framework for Swift language
Https://github.com/railsware/Sleipnir
Https://github.com/Quick/Quick


Rac:ios Responsive Programming Framework Reactivecocoa (RAC) Use example

Xctest's explanation is:--> simple, just create a class and use "test" as the prefix for the test method name.
Xctest is deeply integrated with Xcode and can benefit from Apple's subsequent benefits for xctest upgrades.
The above can be seen xctest is just a very simple to use, so the function is relatively simple, so just can be used in medium and small projects.

"Big" works,--> Kiwi or specta.
Difference:
The kiwi contains Specta and Ocmock as well as expeata all functions.
Specta is no mock and validation function Kiwi.
They can not be used at the same time, but they can be used in combination with each other and xctest. --Cause: They're encapsulating the xctest.

There are pros and cons to the three most tested frameworks in OC above:
Choose Kiwi because you only need to import a Kiwi in Podfile.
Specta need to rely on other third-party libraries for flexibility, but because they are flexible and complex.
With Specta, you also introduce Ocmock/ocmockito and expeata/ochamcrest together.

Ocmock Or Ocmockito
These two are used to mock objects, the stub method, the difference is the use of Ocmock Cubby Ocmockito Library, and the documentation and tutorials richer.
/*
A mock test is a test method that is created in order to be tested with a virtual object for some objects that are not easily constructed or are not easily accessible during the test process.
Mock object, this virtual object is a mock object. Mock objects are substitutes for real objects during commissioning.
*/

Expecta Or Ochamcrest
Is the assertion of the extended framework, expecta immature, the framework has some problems.
Ochamcrest is more mature and scalable, and can customize its assertions and be more flexible.

Specta Framework Summary: In the use of specta, the general will be introduced Ocmock and ochamcrest the two together.

The idea of BDD: not to write code, but to tell a story.
The whole story is made by given ... When ... Then make up.
EG:BDD Framework Kiwi a test code:
Describe (@ "Team", ^{
Context (@ "when newly created", ^{
It (@ "has a name", ^{
ID team = [team Team]; [[Team.name should] equal:@ "Black Hawks"];
});
It (@ "has one players", ^{
ID team = [team Team]; [[[Team should] have:11] players];
});
});
});

This test case is saying given a team,when newly created,it should has a name, and should have one players, basically do not need comments to know what to do.

3. What should we test?
BDD: What we should focus on is "behavior" behaviour rather than testing.
Eg: for example, you design an object that has an interface that defines its methods and dependencies. These methods and dependencies, which declare the conventions of your objects, define how they interact with other parts of the application and what their functions are. They define the behavior of the object. It should also be your goal: to test how your object behaves.

What should not be tested?
Do not test private methods:
(Private method means private, if you feel the need to test a private method, then that private method must contain a conceptual error, usually as a private method, it does too much, thus violating the single principle of responsibility).
Do not stub private methods: Stub private methods and test private methods have the same harm, more importantly, the stub private method will make the program difficult to debug. In general, the library used for stubs relies on some unusual tricks to get the job done, which makes it difficult to find out why a test fails.
Do not test the constructor: the constructor defines the implementation details, and you should not test the constructor, because we agree that the test should be decoupled from the implementation details.
Do not Stub external libraries: third-party code should not appear directly in your tests.

4. Purpose of the test
Make refactoring easier-you can confidently modify implementation details without having to touch the public API.
Avoid code deterioration-when does the deterioration occur? When you change the code.
Provides executable instructions and documentation-when do you want to know how the software actually works? When you want to change them.
Reduced time to create software-how to reduce time? By modifying your code more quickly, the test will confidently tell you where it went wrong when something goes wrong.
Reduces the cost of creating software-time is money, friend.

The test should:
Very fast--tests should be able to be performed frequently.
can be isolated (Isolated)-the test itself cannot rely on external factors or the results of other tests.
Repeatable (REPEATABLE) – Each run of the test should produce the same results.
With self-test (self-verifying)-tests should include assertions that do not require human intervention.
Timely (timely)--the test should be written along with the production code.

5.UI Test

With regard to UI testing, the user's interaction needs to be tested, not the appearance of the app, and UI testing is added to the Xcode7, which can be seen in WWDC Session:406_hd_ui_testing_in_xcode.


Reference Links:
Http://www.cocoachina.com/ios/20150731/12859.html


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Understanding of the iOS test framework

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.