vendredi 20 février 2015

Unit testing with Mockito mocking UIImage

So I am attempting to start developing in a more test driven manner learning to use tests and such and as such i have already come across a vexing issue.


I would like to test that a function i pass an NSArray to then set's an exposed UIScrollview subview third index(first two are default for scroll insets) to be a UIImageView that contains a valid image.


The array i pass in will be of type ALAsset that the method will pull the image out. But i havent gotten that far.


So my first issue is...can i mock an UIImage to be valid i.e not nil in this scenario? or should how I write my tests be approached differently?


so far this is what i have tried



UIImage *mockImage = mock([UIImage class]);
UIImageView *imgView = [[UIImageView alloc]init];

[imgView setImage:mockImage];
NSArray *assets = @[imgView];
[SUT loadImagesForAssets:assets];

NSInteger firstViewIndexOddset = 2;
NSInteger idx = 0;

idx += firstViewIndexOddset;

UIImageView *imgViewFromSUT = [[SUT previewScrollView] subviews][idx];

XCTAssertNotNil(imgViewFromSUT.image);

Aucun commentaire:

Enregistrer un commentaire