mardi 30 juin 2015

Unit testing with `OCMock`

I want to cover MYImageLoader class with unit tests using OCMock. On of the tests makes sure that when it downloads an image it copies the file from the location returned in a NSURLSessionDownloadTask callback to a temporary location. And here I am trying to write a good unit test I do not want to test method implementation details. So I pass a mock of a NSFileManager class in the constructor of MYImageLoader class. But there are several equally possible to use NSFileManager methods to copy a file:

- (BOOL)copyItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL error:(NSError **)error;
- (BOOL)moveItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL error:(NSError **)error;
- (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error;
- (BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error;

So what would be the good practice here? I don’t want my unit tests to determine which methods I should use in the method implementation just to make sure the test passes.

Is there anything like expect this or this or this in OCMock?

Or may be you can advise a different approach?

Aucun commentaire:

Enregistrer un commentaire