1

For some reason my tests are passing every time. Even when I add

fail(@"failed"); 

Xcode still says "test succeeded"

Any ideas?

Heres what my spec looks like

#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 
7
  • 2
    If you are going to downvote the question, at least give some constructive criticism Commented May 3, 2015 at 3:16
  • Probably a dumb question but have you verified that the test itself is being run, either through a log statement or a breakpoint? What happens if you run the tests from the command line via xctool? Commented May 3, 2015 at 5:20
  • Also, I notice that the test block itself is inside the describe method when Kiwi uses the it method for its test blocks. Could that be an issue? Commented May 3, 2015 at 5:21
  • @samsymons Yea. Its being run. Just not failing Commented May 3, 2015 at 5:23
  • 1
    After doing some more research, it looks like this is an issue on the kiwi page, and hasn't been fixed yet. github.com/kiwi-bdd/Kiwi/issues/589 Commented May 3, 2015 at 5:38

1 Answer 1

2

Your code can't fail as it contains no unit tests. Thus, there are zero failures, which Xcode considers as success. You should wrap the code you want to test within an 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"); }); }); 

If you want to learn more on the Kiwi blocks, there a good book on that: https://itunes.apple.com/us/book/test-driving-ios-development/id502345143?ls=1&mt=11.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the answer. Is there somewhere I could find out what each block does?
There's a book on Kiwi, it might help you understand the usually used blocks: itunes.apple.com/us/book/test-driving-ios-development/…
Update: After reading the Kiwi unit testing book, I'm still getting this strange non-error. Take a look - vid.me/P4VD
That's strange, it looks like the tests fail as expected, and shortly after they get unmarked. Does the console give any hints like errors or exceptions, that could trigger this behavior?
The console is still displaying the same test failed messages.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.