The product build succeeds, but the test fails. How do I pass the type-mismatch failure reported on the line with STAssertEquals
below?
// TransactionSpec.m
#import "Transaction.h"
@interface TransactionSpec : SenTestCase
@end
@implementation TransactionSpec
#pragma mark Properties
- (void)testProperties {
Transaction *transaction = [[Transaction alloc] init];
transaction.type = TransactionTypePay;
STAssertNotNil(transaction, @"transaction exists");
STAssertEquals(transaction.type, TransactionTypePay, @"type property works"); // Type mismatch
}
@end
// Transaction.h
typedef enum {
TransactionTypePay,
TransactionTypeCharge
} TransactionType;
@interface Transaction : NSObject
@property (nonatomic) TransactionType *type;
@end
// Transaction.m
#import "Transaction.h"
@implementation Transaction
@syn开发者_Go百科thesize type;
@end
Your type
property is a pointer to a TransactionType
(which is probably not intended) while TransactionTypePay
is an actual TransactionType
.
Your type
property is declared as a pointer to enum, which probably should not be so
Casting transaction.type
to TransactionType
fixes the issue:
STAssertEquals((TransactionType)transaction.type, TransactionTypePay, @"type property works");
But, why should I have to do that since I declare:
@property (nonatomic) TransactionType *type;
精彩评论