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 includes specta and Ocmock and all of Expeata's functions.

The role of the test framework:
Because of the progress of the industry, so we generally 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), which is behavior-driven development. It is designed to solve detailed problems and help developers determine what should be tested.


TDD (Test-driven development). is the test drive development. The whole development is driven by testing.

Gihub The above frame:
OC language above Test frame:
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) using Demo sample

Xctest's explanation:--> simple, just need to create a class. Use "test" as a prefix to the test method name.


Xctest is deeply integrated with Xcode and enjoys the benefits Apple may have for xctest upgrades.


The above can be seen that xctest is only a very easy to use, so the function is also relatively simple, so only can be used in small and medium projects.

"Big" project,--> Kiwi or Specta.
Difference:
The kiwi includes specta and Ocmock as well as expeata all functions.
Specta is no mock and validation function Kiwi.


They are not able to be used at the same time, but they can be mixed 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:
The choice of Kiwi is due to the need to import only one Kiwi in Podfile,
Specta need to rely on other third-party libraries. Flexible. But because of the flexibility and complexity.


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 lies in the use of Ocmock Cubby Ocmockito Library more. and the documentation and tutorials are richer.
/*
The mock test is in the test process. For some objects that are not easy to construct or to get, use a dummy object to create a test method that can be measured.
Mock object, this virtual object is a mock object. A mock object is a substitute for a real object during commissioning.


*/

Expecta Or Ochamcrest
All are assertions of the extended framework, expecta immature, the framework of other problems.


Ochamcrest is more mature and highly scalable, and can define its own assertions and be more flexible.

Summary of the SPECTA framework: when using SPECTA. It is common to introduce Ocmock and ochamcrest together to use the two.

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 Frame 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 example is said given a team,when newly created,it should has a name, and should have one players, basically do not need to stare to know what is doing.

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 declare the conventions of your objects. They define how to interact with other parts of the application and what its functions are.

They define the behavior of the object.

It should also be your goal at the same time: Test the way your object behaves.



What should not be tested?
Do not test private methods:
(Private method means private, assuming you feel the need to test a private method, then that private method must contain a conceptual error, generally as a private method, it does too much, thus violating the principle of single 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. Generally speaking. The library used for stubs relies on some unusual tricks to complete the work, which makes it difficult to find out why a test failed.
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 test.

4. The purpose of testing
Make refactoring easier-you can confidently change the implementation details without having to touch the public API.
Avoid code deterioration-when does the deterioration occur? When you change the code.
Provides instructions and documentation to run-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 changing your code more quickly, the test will confidently tell you where it went wrong.


Reduces the cost of creating software-time is money. Friends.

Test should:
Very high speed (fast)-test should be able to be run often.


can be isolated (Isolated)-the test itself cannot rely on external factors or other test results.


Repeatable (REPEATABLE)-the same results should be produced each time a test is performed.


With self-test (self-verifying)-The test should contain assertions. No human intervention is required.
Timely (timely)-test should be written along with the production code.

5.UI Test

On the UI test, the need to test is the user's interaction, not the application's appearance, Xcode7 new UI testing, detailed to see WWDC Session:406_hd_ui_testing_in_xcode.


References Link:
Http://www.cocoachina.com/ios/20150731/12859.html


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.