Creé la prueba OCUnit en concordancia con "iPhone Development Guide". Aquí está la clase Quiero prueba:OCUnit & NSBundle
// myClass.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface myClass : NSObject {
UIImage *image;
}
@property (readonly) UIImage *image;
- (id)initWithIndex:(NSUInteger)aIndex;
@end
// myClass.m
#import "myClass.m"
@implementation myClass
@synthesize image;
- (id)init {
return [self initWithIndex:0];
}
- (id)initWithIndex:(NSUInteger)aIndex {
if ((self = [super init])) {
NSString *name = [[NSString alloc] initWithFormat:@"image_%i", aIndex];
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
image = [[UIImage alloc] initWithContentsOfFile:path];
if (nil == image) {
@throw [NSException exceptionWithName:@"imageNotFound"
reason:[NSString stringWithFormat:@"Image (%@) with path \"%@\" for current index (%i) wasn't found.",
[name autorelease], path, aIndex]
userInfo:nil];
}
[name release];
}
return self;
}
- (void)dealloc {
[image release];
[super dealloc];
}
@end
Y mi unidad de prueba (LogicTests objetivo):
// myLogic.m
#import <SenTestingKit/SenTestingKit.h>
#import <UIKit/UIKit.h>
#import "myClass.h"
@interface myLogic : SenTestCase {
}
- (void)testTemp;
@end
@implementation myLogic
- (void)testTemp {
STAssertNoThrow([[myClass alloc] initWithIndex:0], "myClass initialization error");
}
@end
Todos los marcos necesarios, "myClass.m" e imágenes añadidas al objetivo. Pero en la acumulación Tengo un error:
[[myClass alloc] initWithIndex:0] raised Image (image_0) with path \"(null)\" for current index (0) wasn't found.. myClass initialization error
Este código (inicialización) funciona bien en la propia aplicación (objetivo principal) y de imagen correcta pantallas posteriores. También revisé la carpeta de mi proyecto (build/Debug-iphonesimulator/LogicTests.octest/
) - hay LogicTests
, Info.plist
y los archivos de imagen necesarios (image_0.png
es uno de ellos).
¿Qué pasa?
edificio fuera de la solución de kpower, me ocurrió lo siguiente [Xcode: PRUEBA vs macros de depuración del preprocesador] (http://stackoverflow.com/questions/6748087/xcode-test-vs-debug-preprocessor-macros/6763597#6763597). – ma11hew28