ios - Kiwi 单元测试在 Xcode 中从未失败

标签 ios objective-c xcode unit-testing kiwi

出于某种原因,我的测试每次都通过了。即使我添加

fail(@"failed");

Xcode 仍然显示“测试成功”

有什么想法吗?

这是我的规范的样子

#import "SDRViewController.h"
#import <UIKit/UIKit.h>
#import <Kiwi/Kiwi.h>

SPEC_BEGIN(SDRViewControllerSpec)

describe(@"SDRViewController", ^{
    __block SDRViewController *viewController = [[SDRViewController alloc]init];

    beforeAll(^{
        [viewController setupCollectionView];
    });
    describe(@"viewController.collectionView", ^{

        describe(@"collectionViewLayout", ^{
            UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)viewController.collectionView.collectionViewLayout;
            [[flowLayout shouldNot]beNil];
            [[theValue(flowLayout.sectionInset) should]equal: theValue(UIEdgeInsetsZero)];
            fail(@"failed");
             });

        });
});

SPEC_END

最佳答案

您的代码不会失败,因为它不包含单元测试。因此,零失败,Xcode 将其视为成功。您应该将要测试的代码包装在 it block 中:

describe(@"collectionViewLayout", ^{
    it(@"has a valid flow layout", ^{
        UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)viewController.collectionView.collectionViewLayout;
        [[flowLayout shouldNot]beNil];
        [[theValue(flowLayout.sectionInset) should]equal: theValue(UIEdgeInsetsZero)];
        fail(@"failed");
    });
});

如果您想了解有关 Kiwi 积木的更多信息,有一本好书:https://itunes.apple.com/us/book/test-driving-ios-development/id502345143?ls=1&mt=11 .

关于ios - Kiwi 单元测试在 Xcode 中从未失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30009852/

相关文章:

c - 如何在编译 clang 时包含 GLUT

objective-c - 保存包含 'Calculation' 字段的 PKTItem 时是否有避免错误的解决方法?

用于 UIScrollViews 内容的 iOS VIewController

ios - 为 iOS 8 构建 Firebase 支持的应用程序时出现链接错误

ios - 如何将一个 ScrollView 图像选择到另一个 ScrollView 中?

objective-c - 如何从 tableView :cellForRowAtIndexPath? 中访问 tableView 单元格的高度

android - 移动应用程序的更新如何进行?

ios - cocos2d-x-2.2.6/Cocos2dx 2.x加速度计倾斜不起作用

objective-c - View Controller 处于横向模式,但我从纵向模式获取框架?

swift - 将附件 View 添加到“打开/保存”对话框时布局约束错误