当前位置:网站首页>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
边栏推荐
- What is the five levels of cultivation of MES management system
- JS Date object
- Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online?
- MySQL practice: 4 Operation of data
- Arrangement and insertion structure
- What is Wi Fi 6 (802.11ax)? Why is Wi Fi 6 important?
- Database learning notes I
- Click the button to call the system browser to open Baidu home page
- PCB miscellaneous mail
- [UVM basics] connect of UVM_ Phase execution sequence
猜你喜欢

JMeter performance testing - Basic Concepts

Seven important reasons for responsive Web Design

My colleague asked a question I never thought about. Why did kubernetes' superfluous' launch the static pod concept?

Uni app installation and project directory (hbuilder configuration)
![[UVM basics] understanding of sequence and sequencer](/img/74/ff451e500d0b7154d7bb95398eaef0.jpg)
[UVM basics] understanding of sequence and sequencer

Ora-12514: tns: the listener currently does not recognize the service requested in the connection descriptor

JS Date object

JS precompile - Variable - scope - closure

Win11 open folder Caton solution summary

Chapter 5 (array)
随机推荐
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
MySQL practice: 4 Operation of data
1010. song backtracking with total duration divisible by 60
Project management learning
[UVM basics] understanding of sequence and sequencer
Crawler case 1: JS reversely obtains HD Wallpapers of minimalist Wallpapers
. eslintrc. JS configuration
我想要股票账户优惠开户,如何操作?手机开户安全么?
4 best practices for wireless (OTA) updates
Use of jupyter notebook
Baoyan postgraduate entrance examination interview - operating system
Yyds dry inventory kubernetes easy service discovery and load balancing (11)
How to define a digital factory and what is the relationship with smart factory and industry 4.0
Web technology sharing | webrtc recording video stream
Color code
Power apps application practice | easily develop employee leave attendance management applet with power apps
Flower instruction WP
Golang collaboration and channel usage
有序排列
Take you three minutes to get started typescript