【问题标题】:OCMockito / OCHamcrest verify array contains object propertyOCMockito / OCHamcrest 验证数组包含对象属性
【发布时间】:2016-03-23 07:18:57
【问题描述】:

我正在创建一个添加一些本地通知的应用程序。 这是我的测试

- (void)testFirstLogin {

//some initials array
NSArray *withoutFriends = @[@"a", @"b", @"c", @"e", @"f"];
NSArray *withFriends = @[@"v", @"w", @"x", @"y", @"z"];

//my service which add local notifications
LocalNotificationService *service = [LocalNotificationService sharedInstance];
service.lastLoginDate = nil;

//UIApplication mock
UIApplication *application = mock([UIApplication class]);
service.applictation = application;

//method which adds notifications
[service addNotificationScheduleFirstLoginWithNoFriendsArray:withoutFriends friendsExistArray:withFriends];

//In this method I create UILocalNotification
/*
 UILocalNotification *localNotification = [[UILocalNotification alloc] init];
 localNotification.alertBody = text;
 */

//and add it to schedule
//[self.applictation scheduleLocalNotification:localNotification];

[verifyCount(application, times(1)) scheduleLocalNotification:anything()]; }

这是正确的,验证成功。 但我需要验证我的 UILocalNotification 对象属性 alertBody 是否在 withoutFriends 数组中。 有办法吗?

【问题讨论】:

  • 你提前知道alertBody会是什么吗?喜欢@"a"
  • 在这种情况下没有朋友,所以我知道 alertBody 将是 withoutFriends 数组中的随机值。

标签: objective-c ocmockito ochamcrest


【解决方案1】:

有一个匹配器isIn,我看到它是missing from the README。与hasProperty匹配器一起,我们可以这样写:

[verifyCount(application, times(1)) scheduleLocalNotification:hasProperty(@"alertBody", isIn(withoutFriends))];

【讨论】:

    猜你喜欢
    • 2020-10-15
    • 2021-11-20
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多