Voici comment vous pouvez commencer:
#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];
approche correcte: Ne mettez aucune substance de l'interface utilisateur dans votre document (windowControllerDidLoadNib) si vous voulez le tester. Une seule responsabilité Comment? Il suffit de mettre en œuvre makeWindowControllers
- (void)makeWindowControllers
{
CustomWindowController *controller = [[CustomWindowController alloc] init];
[self addWindowController:controller];
}
à partir du contrôleur de fenêtre, vous pouvez accéder à votre document à tout moment
- (CustomDocument *)document
{
return [self document];
}