1

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

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
4

1 回答 1

2

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

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 。

于 2015-05-10T12:30:20.687 回答