SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Mock'n'StubMock'n'Stub
OCMock, OCMockito, Nocilla, OHHTTPStubs Sandboxи немногоOCMock, OCMockito, Nocilla, OHHTTPStubs Sandboxи немного
Пирожок Без НиктоПирожок Без Никто
• Создавать дополнительные объектыСоздавать дополнительные объекты
• " "Создавать временную реализацию протокола" "Создавать временную реализацию протокола
• Оставлять затычкиОставлять затычки #ifdef DEBUG ...#ifdef DEBUG ...
• Всякие радости с бэкэндомВсякие радости с бэкэндом
Вот эти ребятаВот эти ребята
• OCMockOCMock
• OCMockitoOCMockito
• NocillaNocilla
• OHHTTPStubsOHHTTPStubs
• Sandboxи немного Sandboxи немного
Два брата-акробатаДва брата-акробата
• mock-Создавать объекты для классовmock-Создавать объекты для классов
OCMClassMockOCMClassMock((aClassaClass))
MKTMockMKTMock((aClassaClass))
• mock-Создавать объекты для протоколовmock-Создавать объекты для протоколов
OCMProtocolMockOCMProtocolMock((aProtocolaProtocol))
MKTMockProtocolMKTMockProtocol((aProtocolaProtocol))
• OCMockitoУ есть дополнительные методыOCMockitoУ есть дополнительные методы
MKTMockObjectAndProtocolMKTMockObjectAndProtocol((aClassaClass,, aProtocolaProtocol))
MKTMockProtocolWithoutOptionalsMKTMockProtocolWithoutOptionals((aProtocolaProtocol))
• OCMockУ есть дополнительные методыOCMockУ есть дополнительные методы
OCMStrictClassMockOCMStrictClassMock((aClassaClass))
OCMStrictProtocolMockOCMStrictProtocolMock((aProtocolaProtocol))
OCMPartialMockOCMPartialMock((aObjectaObject))
OCMObserverMockOCMObserverMock()()
Stubbing methodsStubbing methods
idid<ContentProviderProtocol> contentProvider = ...<ContentProviderProtocol> contentProvider = ...
OCMStubOCMStub([contentProvider([contentProvider loadSomeValuesloadSomeValues]).]).andReturnandReturn((@[@1, @3, @2]@[@1, @3, @2]););
[[MKTGivenMKTGiven([contentProvider([contentProvider loadSomeValuesloadSomeValues])]) willReturnwillReturn::@[@1, @3, @2]@[@1, @3, @2]];];
OCMockitoOCMockito
--willReturnwillReturn%primitiveTypeName%:aValue%primitiveTypeName%:aValue
--willReturnStructwillReturnStruct:aStructPointer:aStructPointer objCTypeobjCType:aType:aType
--willDowillDo:aBlock:aBlock
--willThrowwillThrow:anException:anException
OCMockOCMock
..andReturnandReturn(aValue)(aValue)
..andThrowandThrow(anException)(anException)
..andPostandPost(aNotification)(aNotification)
..andCallandCall(anObject, aSelector)(anObject, aSelector)
..andDoandDo(aBlock)(aBlock)
..andForwardToRealObjectandForwardToRealObject()()
Chaining stub actionsChaining stub actions
OCMStubOCMStub([contentProvider([contentProvider loadSomeValuesloadSomeValues]).]).andReturnandReturn((@[@1, @3,@[@1, @3,
@2]@2]).).andThrowandThrow((willThrowwillThrow:anException);:anException);
[[[[MKTGivenMKTGiven([contentProvider([contentProvider loadSomeValuesloadSomeValues])]) willReturnwillReturn::@[@1, @3, @2]@[@1, @3, @2]]]
willThrowwillThrow:anException];:anException];
Advanced stubbing methodsAdvanced stubbing methods
NSMutableArrayNSMutableArray *mockArray = ...*mockArray = ...
OCMStubOCMStub([mockArray([mockArray addObject:@1addObject:@1]);]);
OCMArgOCMArg *arg =*arg = [[OCMArgOCMArg isKindOfClassisKindOfClass:[:[NSStringNSString classclass]];]];
OCMStubOCMStub([mockArray([mockArray addObjectaddObject:arg]).:arg]).andThrowandThrow(anException);(anException);
OCMArgOCMArg
--isNilisNil
--isNotNilisNotNil
--isNotEqualisNotEqual:aValue:aValue
--isKindOfClassisKindOfClass:aClass:aClass
--checkWithSelectorcheckWithSelector:aSelector:aSelector onObjectonObject:anObject:anObject
--checkWithBlockcheckWithBlock:^:^BOOLBOOL((idid value)blockvalue)block
[[MKTGivenMKTGiven([mockArray([mockArray containsObjectcontainsObject::startsWithstartsWith((@"tes"@"tes")]))]) willReturnBoolwillReturnBool::YESYES];];
Verifying interactionsVerifying interactions
NSMutableArrayNSMutableArray *mockArray = ...*mockArray = ...
[mockArray[mockArray removeObjectremoveObject::@"This is a test"@"This is a test"];];
[[MKTVerifyMKTVerify(mockArray)(mockArray) removeObjectremoveObject::startsWithstartsWith((@"This is"@"This is")];)];
OCMVerifyOCMVerify([mockArray([mockArray removeObjectremoveObject::startsWithstartsWith((@"This is"@"This is")]);)]);
OCMExpectOCMExpect([mockArray([mockArray removeObjectremoveObject::startsWithstartsWith((@"This is"@"This is")]);)]);
OCMExpectOCMExpect([mockArray([mockArray removeAllObjectsremoveAllObjects]);]);
......
OCMVerifyAllOCMVerifyAll(classMock)(classMock)
NocillaNocilla
+ (+ (voidvoid)setUp)setUp
{{
[[[[LSNocillaLSNocilla sharedInstancesharedInstance]] startstart];];
}}
- (- (voidvoid)setUp)setUp
{{
[[[[LSNocillaLSNocilla sharedInstancesharedInstance]] clearStubsclearStubs];];
}}
+ (+ (voidvoid)tearDown)tearDown
{{
[[[[LSNocillaLSNocilla sharedInstancesharedInstance]] stopstop];];
}}
Stubbing requestsStubbing requests
stubRequeststubRequest((@"GET"@"GET",, @"http://mockingbird.getsandbox.com/selectedColor"@"http://mockingbird.getsandbox.com/selectedColor"))
..withHeaderswithHeaders((@{@{@"Accept"@"Accept":: @"application/json"@"application/json"}}))
..andReturnandReturn((200200))
..withHeaderswithHeaders((@{@{@"Content-Type"@"Content-Type":: @"application/json"@"application/json"}}))
..withBodywithBody((@"{"selectedColor":[1, 0, 0, 1]}"@"{"selectedColor":[1, 0, 0, 1]}"););
andReturnRawResponseandReturnRawResponse(aData);(aData);
andFailWithErrorandFailWithError(anError);(anError);
OHHTTPStubsOHHTTPStubs
[[OHHTTPStubsOHHTTPStubs stubRequestsPassingTeststubRequestsPassingTest:^:^BOOLBOOL((NSURLRequestNSURLRequest *request) {*request) {
......
returnreturn isRequestAcceptedByStub;isRequestAcceptedByStub;
}} withStubResponsewithStubResponse:^:^OHHTTPStubsResponseOHHTTPStubsResponse*(*(NSURLRequestNSURLRequest *request) {*request) {
returnreturn httpStubsResponse;httpStubsResponse;
}];}];
OHHTTPStubsResponseOHHTTPStubsResponse
++ responseWithDataresponseWithData::statusCode:headersstatusCode:headers::
++ responseWithFileAtPathresponseWithFileAtPath::statusCode:headersstatusCode:headers::
++ responseWithErrorresponseWithError::
++ responseWithJSONObjectresponseWithJSONObject::statusCodestatusCode::headersheaders::
++ responseWithHTTPMessageDataresponseWithHTTPMessageData::
++ responseNamed:inBundleresponseNamed:inBundle::
SandboxSandbox
Всем спасибо за внимание!Всем спасибо за внимание!
• OCMock -OCMock - http://ocmock.org/http://ocmock.org/
• OCMockito -OCMockito - https://github.com/jonreid/OCMockitohttps://github.com/jonreid/OCMockito
• Nocilla -Nocilla - https://github.com/luisobo/Nocillahttps://github.com/luisobo/Nocilla
• OHHTTPStubs -OHHTTPStubs -
https://github.com/AliSoftware/OHHTTPStubshttps://github.com/AliSoftware/OHHTTPStubs
• Sandbox -Sandbox - https://getsandbox.com/https://getsandbox.com/

Weitere ähnliche Inhalte

Andere mochten auch

Are Top Web Sites Good For Everybody?
Are Top Web Sites Good For Everybody?Are Top Web Sites Good For Everybody?
Are Top Web Sites Good For Everybody?hiddengemtoday1
 
Work Resume Dromerick 2016
Work Resume Dromerick 2016Work Resume Dromerick 2016
Work Resume Dromerick 2016Laura Dromerick
 
Mga teorya at tungkulin ng wikang filipino
Mga teorya at tungkulin ng wikang filipinoMga teorya at tungkulin ng wikang filipino
Mga teorya at tungkulin ng wikang filipinocessai alagos
 
Datix Handler Training manual
Datix Handler Training manualDatix Handler Training manual
Datix Handler Training manualOla Hill
 
Стратегия тестирования - больше чем просто план
Стратегия тестирования - больше чем просто планСтратегия тестирования - больше чем просто план
Стратегия тестирования - больше чем просто планIT61
 
Streaming Music in 2016
Streaming Music in 2016Streaming Music in 2016
Streaming Music in 2016Kern Elliott
 
Thiết kế khu vui chơi trẻ em
Thiết kế khu vui chơi trẻ emThiết kế khu vui chơi trẻ em
Thiết kế khu vui chơi trẻ emnoithatphangia
 
AdvancedTdd
AdvancedTddAdvancedTdd
AdvancedTddjlink
 

Andere mochten auch (11)

Question 4
Question 4Question 4
Question 4
 
Are Top Web Sites Good For Everybody?
Are Top Web Sites Good For Everybody?Are Top Web Sites Good For Everybody?
Are Top Web Sites Good For Everybody?
 
Facebook
FacebookFacebook
Facebook
 
Work Resume Dromerick 2016
Work Resume Dromerick 2016Work Resume Dromerick 2016
Work Resume Dromerick 2016
 
Mga teorya at tungkulin ng wikang filipino
Mga teorya at tungkulin ng wikang filipinoMga teorya at tungkulin ng wikang filipino
Mga teorya at tungkulin ng wikang filipino
 
Datix Handler Training manual
Datix Handler Training manualDatix Handler Training manual
Datix Handler Training manual
 
Стратегия тестирования - больше чем просто план
Стратегия тестирования - больше чем просто планСтратегия тестирования - больше чем просто план
Стратегия тестирования - больше чем просто план
 
Advert research
Advert researchAdvert research
Advert research
 
Streaming Music in 2016
Streaming Music in 2016Streaming Music in 2016
Streaming Music in 2016
 
Thiết kế khu vui chơi trẻ em
Thiết kế khu vui chơi trẻ emThiết kế khu vui chơi trẻ em
Thiết kế khu vui chơi trẻ em
 
AdvancedTdd
AdvancedTddAdvancedTdd
AdvancedTdd
 

Ähnlich wie Mock-n-stub

Coqによる証明駆動開発
Coqによる証明駆動開発Coqによる証明駆動開発
Coqによる証明駆動開発Hiroki Mizuno
 
Process Doppelgänging
Process Doppelgänging Process Doppelgänging
Process Doppelgänging KarlFrank99
 
[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례
[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례
[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례Hwanhee Kim
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Thinking Outside The [Sand]Box
Thinking Outside The [Sand]BoxThinking Outside The [Sand]Box
Thinking Outside The [Sand]BoxMichael Genkin
 
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Daniel Bohannon
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectYen-Chin Lee
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Hiroki Mizuno
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBMongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBBoxed Ice
 

Ähnlich wie Mock-n-stub (11)

Coqによる証明駆動開発
Coqによる証明駆動開発Coqによる証明駆動開発
Coqによる証明駆動開発
 
Process Doppelgänging
Process Doppelgänging Process Doppelgänging
Process Doppelgänging
 
[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례
[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례
[NDC2017] 딥러닝으로 게임 콘텐츠 제작하기 - VAE를 이용한 콘텐츠 생성 기법 연구 사례
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Thinking Outside The [Sand]Box
Thinking Outside The [Sand]BoxThinking Outside The [Sand]Box
Thinking Outside The [Sand]Box
 
Rubygems And You
Rubygems And YouRubygems And You
Rubygems And You
 
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
 
Splash
SplashSplash
Splash
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto project
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBMongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
 

Kürzlich hochgeladen

Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4wistariecz
 
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)River / Thao Phan
 
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...Nitya salvi
 
How to order fake Worcester State University diploma?
How to order fake Worcester State University diploma?How to order fake Worcester State University diploma?
How to order fake Worcester State University diploma?melodolykelton
 
Ignite Your Brand: Tailored Creative Solutions Proposal
Ignite Your Brand: Tailored Creative Solutions ProposalIgnite Your Brand: Tailored Creative Solutions Proposal
Ignite Your Brand: Tailored Creative Solutions ProposalCreative Labs
 
Jaro je tady - Spring is here (Judith) 2
Jaro je tady - Spring is here (Judith) 2Jaro je tady - Spring is here (Judith) 2
Jaro je tady - Spring is here (Judith) 2wistariecz
 
Turn Off The Air Con - The Singapore Punk Scene
Turn Off The Air Con - The Singapore Punk SceneTurn Off The Air Con - The Singapore Punk Scene
Turn Off The Air Con - The Singapore Punk SceneLuca Vergano
 
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
LESSON-1-MUSIC-Q4 also a reviewer mapeh.pptx
LESSON-1-MUSIC-Q4 also a reviewer mapeh.pptxLESSON-1-MUSIC-Q4 also a reviewer mapeh.pptx
LESSON-1-MUSIC-Q4 also a reviewer mapeh.pptxmatthewmirafuentes
 
一比一原版(YU学位证书)约克大学毕业证学历认证新版办理
一比一原版(YU学位证书)约克大学毕业证学历认证新版办理一比一原版(YU学位证书)约克大学毕业证学历认证新版办理
一比一原版(YU学位证书)约克大学毕业证学历认证新版办理txkonu
 
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Sheetaleventcompany
 
codes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptxcodes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptx17duffyc
 
Headshots and Personal Branding by Julie King Photography
Headshots and Personal Branding by Julie King PhotographyHeadshots and Personal Branding by Julie King Photography
Headshots and Personal Branding by Julie King PhotographyJulie King Photography
 
Van Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson todayVan Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson todaylucygibson17
 
Jaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Jaunpur
Jaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime JaunpurJaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Jaunpur
Jaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Jaunpurmeghakumariji156
 
Digital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic PrintsDigital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic PrintsMatte Image
 
SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)
SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)
SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)River / Thao Phan
 
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service AvailableCall Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service AvailableNitya salvi
 
Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...
Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...
Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...meghakumariji156
 
Sui Generis Magazine volume one Kristen Murillo.pdf
Sui Generis Magazine volume one Kristen Murillo.pdfSui Generis Magazine volume one Kristen Murillo.pdf
Sui Generis Magazine volume one Kristen Murillo.pdfkristenmurillo218
 

Kürzlich hochgeladen (20)

Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4Jaro je tady - Spring is here (Judith) 4
Jaro je tady - Spring is here (Judith) 4
 
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
SB_ Dragons Riders of Berk_ Rough_ RiverPhan (2024)
 
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
Just Call Vip call girls Farrukhabad Escorts ☎️8617370543 Two shot with one g...
 
How to order fake Worcester State University diploma?
How to order fake Worcester State University diploma?How to order fake Worcester State University diploma?
How to order fake Worcester State University diploma?
 
Ignite Your Brand: Tailored Creative Solutions Proposal
Ignite Your Brand: Tailored Creative Solutions ProposalIgnite Your Brand: Tailored Creative Solutions Proposal
Ignite Your Brand: Tailored Creative Solutions Proposal
 
Jaro je tady - Spring is here (Judith) 2
Jaro je tady - Spring is here (Judith) 2Jaro je tady - Spring is here (Judith) 2
Jaro je tady - Spring is here (Judith) 2
 
Turn Off The Air Con - The Singapore Punk Scene
Turn Off The Air Con - The Singapore Punk SceneTurn Off The Air Con - The Singapore Punk Scene
Turn Off The Air Con - The Singapore Punk Scene
 
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Aligarh Just Call 8617370543 Top Class Call Girl Service Available
 
LESSON-1-MUSIC-Q4 also a reviewer mapeh.pptx
LESSON-1-MUSIC-Q4 also a reviewer mapeh.pptxLESSON-1-MUSIC-Q4 also a reviewer mapeh.pptx
LESSON-1-MUSIC-Q4 also a reviewer mapeh.pptx
 
一比一原版(YU学位证书)约克大学毕业证学历认证新版办理
一比一原版(YU学位证书)约克大学毕业证学历认证新版办理一比一原版(YU学位证书)约克大学毕业证学历认证新版办理
一比一原版(YU学位证书)约克大学毕业证学历认证新版办理
 
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
Call Girl In Chandigarh ☎ 08868886958✅ Just Genuine Call Call Girls Chandigar...
 
codes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptxcodes and conventions of film magazine and website.pptx
codes and conventions of film magazine and website.pptx
 
Headshots and Personal Branding by Julie King Photography
Headshots and Personal Branding by Julie King PhotographyHeadshots and Personal Branding by Julie King Photography
Headshots and Personal Branding by Julie King Photography
 
Van Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson todayVan Gogh Powerpoint for art lesson today
Van Gogh Powerpoint for art lesson today
 
Jaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Jaunpur
Jaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime JaunpurJaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Jaunpur
Jaunpur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Jaunpur
 
Digital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic PrintsDigital C-Type Printing: Revolutionizing The Future Of Photographic Prints
Digital C-Type Printing: Revolutionizing The Future Of Photographic Prints
 
SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)
SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)
SB_ Scott Pilgrim_ Rough_ RiverPhan (2024)
 
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service AvailableCall Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
Call Girls Varanasi Just Call 8617370543Top Class Call Girl Service Available
 
Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...
Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...
Top Rated Lucknow Escorts Service, ₹5000 Best Hot Call Girls With Room +91-82...
 
Sui Generis Magazine volume one Kristen Murillo.pdf
Sui Generis Magazine volume one Kristen Murillo.pdfSui Generis Magazine volume one Kristen Murillo.pdf
Sui Generis Magazine volume one Kristen Murillo.pdf
 

Mock-n-stub

  • 1. Mock'n'StubMock'n'Stub OCMock, OCMockito, Nocilla, OHHTTPStubs Sandboxи немногоOCMock, OCMockito, Nocilla, OHHTTPStubs Sandboxи немного
  • 2. Пирожок Без НиктоПирожок Без Никто • Создавать дополнительные объектыСоздавать дополнительные объекты • " "Создавать временную реализацию протокола" "Создавать временную реализацию протокола • Оставлять затычкиОставлять затычки #ifdef DEBUG ...#ifdef DEBUG ... • Всякие радости с бэкэндомВсякие радости с бэкэндом
  • 3.
  • 4. Вот эти ребятаВот эти ребята • OCMockOCMock • OCMockitoOCMockito • NocillaNocilla • OHHTTPStubsOHHTTPStubs • Sandboxи немного Sandboxи немного
  • 5. Два брата-акробатаДва брата-акробата • mock-Создавать объекты для классовmock-Создавать объекты для классов OCMClassMockOCMClassMock((aClassaClass)) MKTMockMKTMock((aClassaClass)) • mock-Создавать объекты для протоколовmock-Создавать объекты для протоколов OCMProtocolMockOCMProtocolMock((aProtocolaProtocol)) MKTMockProtocolMKTMockProtocol((aProtocolaProtocol)) • OCMockitoУ есть дополнительные методыOCMockitoУ есть дополнительные методы MKTMockObjectAndProtocolMKTMockObjectAndProtocol((aClassaClass,, aProtocolaProtocol)) MKTMockProtocolWithoutOptionalsMKTMockProtocolWithoutOptionals((aProtocolaProtocol)) • OCMockУ есть дополнительные методыOCMockУ есть дополнительные методы OCMStrictClassMockOCMStrictClassMock((aClassaClass)) OCMStrictProtocolMockOCMStrictProtocolMock((aProtocolaProtocol)) OCMPartialMockOCMPartialMock((aObjectaObject)) OCMObserverMockOCMObserverMock()()
  • 6. Stubbing methodsStubbing methods idid<ContentProviderProtocol> contentProvider = ...<ContentProviderProtocol> contentProvider = ... OCMStubOCMStub([contentProvider([contentProvider loadSomeValuesloadSomeValues]).]).andReturnandReturn((@[@1, @3, @2]@[@1, @3, @2]);); [[MKTGivenMKTGiven([contentProvider([contentProvider loadSomeValuesloadSomeValues])]) willReturnwillReturn::@[@1, @3, @2]@[@1, @3, @2]];]; OCMockitoOCMockito --willReturnwillReturn%primitiveTypeName%:aValue%primitiveTypeName%:aValue --willReturnStructwillReturnStruct:aStructPointer:aStructPointer objCTypeobjCType:aType:aType --willDowillDo:aBlock:aBlock --willThrowwillThrow:anException:anException OCMockOCMock ..andReturnandReturn(aValue)(aValue) ..andThrowandThrow(anException)(anException) ..andPostandPost(aNotification)(aNotification) ..andCallandCall(anObject, aSelector)(anObject, aSelector) ..andDoandDo(aBlock)(aBlock) ..andForwardToRealObjectandForwardToRealObject()()
  • 7. Chaining stub actionsChaining stub actions OCMStubOCMStub([contentProvider([contentProvider loadSomeValuesloadSomeValues]).]).andReturnandReturn((@[@1, @3,@[@1, @3, @2]@2]).).andThrowandThrow((willThrowwillThrow:anException);:anException); [[[[MKTGivenMKTGiven([contentProvider([contentProvider loadSomeValuesloadSomeValues])]) willReturnwillReturn::@[@1, @3, @2]@[@1, @3, @2]]] willThrowwillThrow:anException];:anException];
  • 8. Advanced stubbing methodsAdvanced stubbing methods NSMutableArrayNSMutableArray *mockArray = ...*mockArray = ... OCMStubOCMStub([mockArray([mockArray addObject:@1addObject:@1]);]); OCMArgOCMArg *arg =*arg = [[OCMArgOCMArg isKindOfClassisKindOfClass:[:[NSStringNSString classclass]];]]; OCMStubOCMStub([mockArray([mockArray addObjectaddObject:arg]).:arg]).andThrowandThrow(anException);(anException); OCMArgOCMArg --isNilisNil --isNotNilisNotNil --isNotEqualisNotEqual:aValue:aValue --isKindOfClassisKindOfClass:aClass:aClass --checkWithSelectorcheckWithSelector:aSelector:aSelector onObjectonObject:anObject:anObject --checkWithBlockcheckWithBlock:^:^BOOLBOOL((idid value)blockvalue)block [[MKTGivenMKTGiven([mockArray([mockArray containsObjectcontainsObject::startsWithstartsWith((@"tes"@"tes")]))]) willReturnBoolwillReturnBool::YESYES];];
  • 9. Verifying interactionsVerifying interactions NSMutableArrayNSMutableArray *mockArray = ...*mockArray = ... [mockArray[mockArray removeObjectremoveObject::@"This is a test"@"This is a test"];]; [[MKTVerifyMKTVerify(mockArray)(mockArray) removeObjectremoveObject::startsWithstartsWith((@"This is"@"This is")];)]; OCMVerifyOCMVerify([mockArray([mockArray removeObjectremoveObject::startsWithstartsWith((@"This is"@"This is")]);)]); OCMExpectOCMExpect([mockArray([mockArray removeObjectremoveObject::startsWithstartsWith((@"This is"@"This is")]);)]); OCMExpectOCMExpect([mockArray([mockArray removeAllObjectsremoveAllObjects]);]); ...... OCMVerifyAllOCMVerifyAll(classMock)(classMock)
  • 10. NocillaNocilla + (+ (voidvoid)setUp)setUp {{ [[[[LSNocillaLSNocilla sharedInstancesharedInstance]] startstart];]; }} - (- (voidvoid)setUp)setUp {{ [[[[LSNocillaLSNocilla sharedInstancesharedInstance]] clearStubsclearStubs];]; }} + (+ (voidvoid)tearDown)tearDown {{ [[[[LSNocillaLSNocilla sharedInstancesharedInstance]] stopstop];]; }}
  • 11. Stubbing requestsStubbing requests stubRequeststubRequest((@"GET"@"GET",, @"http://mockingbird.getsandbox.com/selectedColor"@"http://mockingbird.getsandbox.com/selectedColor")) ..withHeaderswithHeaders((@{@{@"Accept"@"Accept":: @"application/json"@"application/json"}})) ..andReturnandReturn((200200)) ..withHeaderswithHeaders((@{@{@"Content-Type"@"Content-Type":: @"application/json"@"application/json"}})) ..withBodywithBody((@"{"selectedColor":[1, 0, 0, 1]}"@"{"selectedColor":[1, 0, 0, 1]}");); andReturnRawResponseandReturnRawResponse(aData);(aData); andFailWithErrorandFailWithError(anError);(anError);
  • 12. OHHTTPStubsOHHTTPStubs [[OHHTTPStubsOHHTTPStubs stubRequestsPassingTeststubRequestsPassingTest:^:^BOOLBOOL((NSURLRequestNSURLRequest *request) {*request) { ...... returnreturn isRequestAcceptedByStub;isRequestAcceptedByStub; }} withStubResponsewithStubResponse:^:^OHHTTPStubsResponseOHHTTPStubsResponse*(*(NSURLRequestNSURLRequest *request) {*request) { returnreturn httpStubsResponse;httpStubsResponse; }];}]; OHHTTPStubsResponseOHHTTPStubsResponse ++ responseWithDataresponseWithData::statusCode:headersstatusCode:headers:: ++ responseWithFileAtPathresponseWithFileAtPath::statusCode:headersstatusCode:headers:: ++ responseWithErrorresponseWithError:: ++ responseWithJSONObjectresponseWithJSONObject::statusCodestatusCode::headersheaders:: ++ responseWithHTTPMessageDataresponseWithHTTPMessageData:: ++ responseNamed:inBundleresponseNamed:inBundle::
  • 14.
  • 15. Всем спасибо за внимание!Всем спасибо за внимание! • OCMock -OCMock - http://ocmock.org/http://ocmock.org/ • OCMockito -OCMockito - https://github.com/jonreid/OCMockitohttps://github.com/jonreid/OCMockito • Nocilla -Nocilla - https://github.com/luisobo/Nocillahttps://github.com/luisobo/Nocilla • OHHTTPStubs -OHHTTPStubs - https://github.com/AliSoftware/OHHTTPStubshttps://github.com/AliSoftware/OHHTTPStubs • Sandbox -Sandbox - https://getsandbox.com/https://getsandbox.com/