IOS applications use GH-Unit for Unit testing

Source: Internet
Author: User

IOSApplication UsageGH-UnitProceedUnit TestThis is the content to be introduced in this article. If you don't want to talk about it, go directly to the topic and first introduce the content framework.

Unit Test iOSXcode framework project management

1. Objective of Unit Testing

2. Ensure code correctness

Support for future code refactoring

1. Basic Environment:

2. computers using the apple System

XCode

GH-Unit is a powerful Unit testing framework developed by Gabriel Handford. Some configurations are required for Unit testing using GH-Unit.

Create a project and add a test Target)

I have created a New "Window-based Application". After the New Application is created, I try "Build and Run" to ensure that the program can be started properly. on Targets, right-click and select "Add-New Target ..."

The Target name can be Tests or similar.

Download the GH-Unit framework and add the necessary framework to the project.

: Https://github.com/downloads/gabriel/gh-unit/GHUnit-0.4.28.zip

Decompress the package and drag it to XCode. Copy the source code to the project and set the target to Tests.

Open the target Tests for configuration, set the target dependency to the first target, and add the CoreGraphics, Foundation, and UIKit frameworks.

Check "Framework Search Paths"

Check whether the "Framework Search Paths" parameter points to the parent directory of GHUnitiOS. framework. This parameter is correct by default.

Add the "-Objc" and "-all_load" parameters for "Other Linker Flags" of the test target.

Modify Tests-Info.plist files

Modify the "Main nib file base name" parameter to clear the default value "MainWindow.

Add GHUnitIOSTestMain. m (http://github.com/gabriel/gh-unit/blob/master/Project-IPhone/GHUnitIOSTestMain.m)

Drag the downloaded package to Other Sources, copy it to the project, and select the target as the test project.

(Optional) Create Tests_Prefix.pch.

Copy a file from the original GHUnitExample_Prefix.pch, rename it Tests_Prefix.pch, and add it to the project using XCode.

Modify Tests_Prefix.pch to add # import <GHUnitIOS/GHUnit. h> to the mobile device platform. After adding the file, you do not need to reference the library in the created test code.

Finally, modify the configuration file of the Tests target and search for GCC_Prefix to Tests_Prefix.pch.

(Optional) set the Makefile file.

Create Test

To facilitate source code management, create Tests in the project directory and import it to XCode.

Add a test class under the Tests group to test whether the configuration is correct. Name it "SetupTests" and inherit from NSObject without generating header files.

Run the test

Select the Tests target Build and Run to Run the iPhone simulator to start the unit test. If there is a problem, check that the Tests-Info.plist configuration is correct.

Summary:IOSApplication UsageGH-UnitProceedUnit TestI hope this article will help you.

Related Article

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.