Unit Testing of iPhone Applications



Unit testing lets you specify behavior that your code must exhibit to ensure that its functionality remains unchanged as you modify it to, for example, make performance improvements or fix bugs. A test case exercises your code in a specific way; if the results vary from the expected results, the test case fails. A test suite is made up of a set of test cases. You can develop one or more test suites to test different aspects of your code.


Unit tests are the basis of test-driven development, which is a style of writing code in which you write test cases before writing the code to be tested. This development approach lets you codify requirements and edge cases for your code before you get down to writing it. After writing the test cases, you develop your algorithms with the aim of passing your test cases. After your code passes the test cases, you have a foundation upon which you can make improvements to your code, with confidence that any changes to the expected behavior (which would result in bugs in your product) are identified the next time you run the tests.


Even when not using test-driven development, unit tests can help reduce the introduction of bugs in your code. You can incorporate unit testing in a working application to ensure that future source-code changes don’t modify the application’s behavior. As you fix bugs, you can add test cases that confirm the bugs are fixed. However, adding unit tests to a project that’s not designed with unit testing in mind may require rearchitecting or refactoring parts of the code to make them testable.


The Xcode unit-testing environment is based on the open-source SenTestingKit framework. This framework provides a set of classes and command-line tools that let you design test suites and run them on your code.


Xcode offers two types of unit tests: logic tests and application tests.


Logic tests. These tests check the correct functionality of your code in a clean-room environment; that is, your code is not run inside an application. Logic tests let you put together very specific test cases to exercise your code at a very granular level (a single method in class) or as part of a workflow. You can use logic tests to perform stress-testing of your code to ensure that it behaves correctly in extreme situations that are unlikely in a running application. These tests help you produce robust code that works correctly when used in ways that you did not anticipate.


Application tests. These tests check the functionality of your code in a running application. You can use application tests to ensure that the connections of your user-interface controls remain in place, and that your controls and controller objects work correctly with your object model as you work on your application. Because application tests run only on a device, you can also use these tests to perform hardware testing, such as getting the location of the device.

Editor: ankita Added on: 2013-03-07 15:46:07 Total View:294







Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---