出于某种原因,我的测试每次都通过了。即使我添加
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/