当前位置:网站首页>GHUnit: Unit Testing Objective-C for the iPhone
GHUnit: Unit Testing Objective-C for the iPhone
2022-06-26 08:10:00 【may_he】
GHUnit is a test framework for Objective-C that runs on Mac OS X 10.5 and above and iPhone 3.x and above. It can be used standalone or with other testing frameworks like SenTestingKit or GTM.
These notes are for XCode 3.2.5. You can assume these steps are fragile and you need to follow them to the letter.
Setting Up the Environment
- Start XCode and create a new project by selecting New Project under the File menu,
- In the New Project popup, in the left column, select Application under iPhone OS. In the upper right panel, select Window-Based Application,
- Select your device type. Chose iPhone for this example.
- Provide a name and a location. For this example, I will use the name Calculator and the directory will be the /Users/Nearsoft/Desktop.
- Now run your application. Use
-r or from the pull-down menu Build > Build and Run.
- As a result you should see the simulator, like this,
- Now, quit the simulator and switch back to XCode.
Adding GHUnit Framework to Our Project.
- Download the last version of GHUnit Framework (as of this writing, it is 0.4.27) from here.
- Unzip the ZIP file in the same directory where you saved your project. This will create the directory GHUnitIOS.framework.
- Add a new target to your project. Control-click (right-click) on Targets and select Add - New Target.
- In the left column select iOS - Cocoa Touch and Application. Give it a descriptive name. For this example, I will use UnitTests.
- We need to add a few Frameworks to our new Target. Right-click on our target, select then Add and then choose Existing Frameworks. Lets add these three,
- CoreGraphics.framework
- Foundation.framework
- UIKit.framework
- To add the GHUnitIOS.framework, you need click on the “Add Other…” button and choose the GHUnitIOS.framework directory which just unzipped in step 9, above.
- If you've done this right so far, you will see something like this,
Add a few linker flags to our project
- Choose the UnitTests target, control-click on it and choose Get info.
- Tab and look for Other Linker Flags and double-click on that option.
- Add the following,
- -ObjC
- Add: -all_load
- Close that dialog.
- Once you add the flags you will see something like the image bellow,
- Look for the UnitTests-Info.plist in the Groups & Files column, and edit the option Main nib file base name. Then, delete this value (i.e., by clearing the field) and save it.
Add the GHUnitIOSTestMain.m
- Download GHUnitIOSTestMain. You can download it form here.
- Create a new Group in our project. I will call it UnitTests.
- Inside UnitTests Group add the GHUnitIOSTestMain.m,
- Right click on UnitTests Group, select Add – Existing Files…
- Look for the file just download and double-click on it.
- Checkmark Copy items into destination group's folder (if needed), and then click the Add button.
- Once you do that, Build and Run the UnitTests target.
NOTE: if you have a compilation error in the line #import <GHUnitIOS/GHUnit.h> change it for #import <GHUnit/GHUnit.h>
- If you see this image, you've done well.
Create a Test
- Under the UnitTest Group, right click select Add - New File, an Objective-C class (under iOS – Cocoa Touch Class).
- Name it FirstTest.m. For Unit Test files, we do not need create a header file. So uncheck the option Also create "…".h. Verify that UnitTeststarget is selected.
- Then click Finish
- Enter this code in the FirstTest.m file,
//
// FirstTest.m
// Calculator
//
// Created by Jesus Guerra on 3/9/11.
// Copyright 2011 Nearsoft. All rights reserved.
//
#import
@interface FirstTest : GHTestCase {
NSString *stringValue;
}
@end
@implementation FirstTest
-(void)setUp {
stringValue= @"Hello World";
}
-(void)tearDown {
stringValue= nil;
}
-(void)testCompareTwoStrings {
GHAssertEquals(@"", stringValue, @"The value is not the same than '%@'", stringValue);
}
@end - You will then have something like this,
- After that, Build and Run UnitTest target.
- When the simulator shows up, tap on Run. The test will fail, so just go back to your code and change the assertion in the method testCompareTwoStrings,
GHAssertEquals(@"Hello World", someVariableToInitialize, @"The value is not the same as '%@'", someVariableToInitialize);
And Finally …
Congratulations, we did it!
转载自:http://www.nearsoft.com/blog/printblog.html?index_php?view=article&id=305&tmpl=component&print=1
边栏推荐
- Take you three minutes to get started typescript
- 1010. song backtracking with total duration divisible by 60
- Chapter 5 (array)
- Click the button to call the system browser to open Baidu home page
- JWT in go
- Uniapp scrolling load (one page, multiple lists)
- Wifi-802.11 2.4G band 5g band channel frequency allocation table
- This article will take you to learn in detail what is FTTH
- I want to create SQL data (storage structure)
- Informatics Orsay all in one 1354: bracket matching test
猜你喜欢

The 9th zero code training camp is officially open for registration! (Beijing, Shanghai, Guangzhou and Shenzhen)

StarWar armor combined with scanning target location

ASP. Net and Net framework and C #

MySQL practice: 4 Operation of data

Detailed explanation and code implementation of soft voting and hard voting mechanism in integrated learning

OSPF design principles, commands take H3C as an example

ReW_ p

Webrtc has become the official standard of W3C and IETF, and mobile terminal development

Tsinghua Yaoban chendanqi won Sloan award! He is a classmate with last year's winner Ma Tengyu. His doctoral thesis is one of the hottest in the past decade

Opencv mouse event + interface interaction drawing rectangle polygon selection ROI
随机推荐
Uni app is similar to Taobao in selecting multiple specifications of commodities (inventory judgment)
Detailed explanation of the generate go file command of import in golang (absolute detail)
Crawler case 1: JS reversely obtains HD Wallpapers of minimalist Wallpapers
h5 localStorage
Pic 10B parsing
信息学奥赛一本通 1355:字符串匹配问题(strs)
Project practice: parameters of pycharm configuration for credit card digital recognition and how to use opencv in Anaconda
[UVM basics] TLM common data receiving and sending and data receiving examples
MFC writes a suggested text editor
Handwritten instanceof underlying principle
Database learning notes II
Chapter VI (pointer)
Power apps application practice | easily develop employee leave attendance management applet with power apps
Jz-063- median in data stream
Yyds dry inventory kubernetes easy service discovery and load balancing (11)
Household enterprises use WMS warehouse management system. What are the changes
Comparison version number [leetcode]
2: String insert
Oracle 19C local listener configuration error - no listener
项目管理学习