이 시작할 수있는 방법입니다 :
#import <Cocoa/Cocoa.h>
#import <XCTest/XCTest.h>
#import "Document.h"
@interface DocumentTests : XCTestCase {
Document *document;
NSWindowController *controller
}
@end
@implementation DocumentTests
- (void)setUp {
document = [[Document alloc] init];
[document makeWindowControllers];
controller = (NSWindowController *)[document windowControllers][0];
}
- (void)testLoadingWindow
{
XCTAssertNotNil(controller.window);
}
- (void)testTextFieldOutletsIsConnected
{
[controller window]; //kick off window loading
XCTAssertNotNil(document.textField);
}
//For asynchronous testing use XCTestExpectation
//[self expectationWithDescription:@"Expectations"];
//[self waitForExpectationsWithTimeout:3.0 handler:nil];
올바른 접근 방식 : 당신이 그것을 테스트하려는 경우 이 문서 (windowControllerDidLoadNib)에 어떤 UI 물건을 넣지 마십시오. 단일 책임. 방법? 그냥 당신이 언제
- (CustomDocument *)document
{
return [self document];
}
문서에 액세스 할 수 있습니다 창 컨트롤러에서 makeWindowControllers
- (void)makeWindowControllers
{
CustomWindowController *controller = [[CustomWindowController alloc] init];
[self addWindowController:controller];
}
를 구현