티스토리 뷰

As you already know that, to develop an application we need to use always some test framework.


Actually following two keywords are very common.


 - BDD (Behavior Driven Development)


 - TDD (Test Driven Development) 



In a project, I am using Kiwi framework to do unit test.


Today I found a weird behavior from Kiwi.


Let's see this code.


#import "Kiwi.h"

#import "KWSpec+WaitFor.h"


@interface MyInterface : NSObject


-(NSString *)speak:(NSString *)str;


@end


@implementation MyInterface

-(NSString *)speak:(NSString *)str {

    return [NSString stringWithFormat:@"I'm speaking %@", str];

}


@end


SPEC_BEGIN(MyKiwiTest)


__block MyInterface *myObj;


beforeAll(^{

    myObj = [[MyInterface alloc] init];

});



describe(@"My Kiwi Test", ^{

    

    context(@"Selector Test", ^{

        

        it(@"Log String", ^{

            [[myObj should] receive:@selector(speak:)];

            NSLog(@"%@", [myObj speak:@"to YOU!!"]);

        });


    });

    

});


SPEC_END 



With this code you will get this log message : 


2013-05-22 22:45:11.179 MyKiwiTest[70475:c07] (null)


What's wrong with it? I just set the expectation, and then this selector was not called....;(


It seems like to have a bug.



But, let's change the position of expectation like this


context(@"Selector Test", ^{

        [[myObj should] receive:@selector(speak:)];

        

        it(@"Log String", ^{

            NSLog(@"%@", [myObj speak:@"to YOU!!"]);

        });


});


Finally you get this log message : 


2013-05-22 22:46:23.981 MyKiwiTest[77556:c07] I'm speaking to YOU!!


I couldn't find the right reason, but there is a key to find the reason.


in KWExample interface has this selector :


- (void)visitItNode:(KWItNode *)aNode;


And I think, the running cycle of this selector causes this problem.



Anyhow you can face some problem with Unit test because of this situation.


And this way is just a kind of tipp to perform the selector.


Therefore, please be careful to write test codes.


thx


2013-08-09 update


!!! It was not a Bug !!!



If you prevent this kind of error, just call 'andReturn:@YES' .

ex : 

[[myObj should] receive:@selector(speak:) andReturn:@YES];


Then you will not face this problem anymore!! :D


Thanks :)




공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함