NLTHTTPStubServer ã使ã£ã¦ iOS ã¢ããªã®éä¿¡å¨ãã®ãã¹ããæ¸ãã
ãã¹ãå®è¡æã«ã¢ãã¯ã¨ãªã Web ãµã¼ããèµ·åãã¦ãæãéãã®ã¬ã¹ãã³ã¹ãè¿ãç°å¢ãä½ãã NLTHTTPStubServer ã¨ãããã¼ã«ããããããã使ãã°ãweb API ã®å®è¡ã®æåã»ä¸æåãªã©ã®ãã¹ãã楽ã«æ¸ããããã¹ãå®è¡æã«å©ã API ã® URL ãã¡ããã£ã¨æ¸ãæããã ããªã®ã§ããã¹ãã®ããã«ã³ã¼ããä¿®æ£ããé¨åã¯å°ãªãã ããããå®éã®ã¢ããªã±ã¼ã·ã§ã³ã®åä½ã¨ã»ã¼åãç¶æ ã§ãã¹ããã§ããã¯ãã ã
NLTHTTPStubServer ã®å°å ¥
NLTHTTPStubServer ã¯ä»¥ä¸ã®ã©ã¤ãã©ãªã«ä¾åãã¦ããã®ã§ãããããããã¸ã§ã¯ãã«è¿½å ããã
- CocoaHTTPServer - https://github.com/robbiehanson/CocoaHTTPServer
- CocoaAsyncSocket - CocoaHTTPServer ã® Vendor ã«å ¥ã£ã¦ãã
- CocoaLumberjack - CocoaHTTPServer ã® Vendor ã«å ¥ã£ã¦ãã
NLTHTTPStubServer ã®ã½ã¼ã¹ã³ã¼ã㯠github ã§å
¬éããã¦ããã®ã§ããããåå¾ããã
https://github.com/yaakaito/NLTHTTPStubServer
NLTHTTPStubServer ã®ã½ã¼ã¹ã³ã¼ããããã¸ã§ã¯ãã«è¿½å ããããNLTHTTPStubServer 㯠ARC ã使ã£ã¦ããªãã®ã§ãã½ã¼ã¹ã³ã¼ãã追å ããã NLTHTTPStubServer ã®ãã¡ã¤ã«ç¾¤ã®ã³ã³ãã¤ã©ãã©ã°ã« -fno-objc-arc ãã¤ããã
æå¾ã«ä»¥ä¸ã®æ¨æºãã¬ã¼ã ã¯ã¼ã¯ãããã¸ã§ã¯ãã«è¿½å ããã°å°å ¥å®äºã ã
- CFNetwork.framework
- Security.framework
ãã¹ããæ¸ã
NLTHTTPStubServer ã使ã£ã¦ä½ãç°¡å㪠API ã¯ã©ã¤ã¢ã³ããä½ã£ã¦ãã®ãã¹ããæ¸ãã¦ã¿ãããä»å㯠coderwall (http://coderwall.com) ã¨ãããµã¤ãã®ã¦ã¼ã¶ãããã£ã¼ã«ãåå¾ãã API ã¯ã©ã¤ã¢ã³ããä½ã£ã¦ã¿ããAPIã«ã¤ãã¦ã®èª¬æã¯ããã«æ¸ãã¦ããã http://coderwall.com/api
ãã¹ã㯠GHUnit ã使ã£ã¦æ¸ããã
ã¾ãããããã¯ã¼ã¯ã©ã¤ãã©ãªã¯ AFNetworking ã使ã£ãã
以ä¸ã®ãããªæãã§ä½¿ããã¯ã©ã¤ã¢ã³ãã«ãªãã¨ããã®ããªã
block ã§APIã®å®è¡ãæåããæã¨å¤±æããæã®å¦çã渡ãã¦ãããæãã
GHUnit ã®ãã¹ãã¯ã©ã¹ CoderwallAPIClientTest ãä½æãããéåæã®ãã¹ãããããã®ã§ GHAsyncTestCase ã®ãµãã¯ã©ã¹ã¨ããã
ãã¹ãã®ããã«APIã®å®è¡çµæããã¡ã¤ã«ã«ä¿åããã
curl http://coderwall.com/slightair.json -o slightair.json
ããã«åå¨ããªãã¦ã¼ã¶åãæå®ããã¨ã¹ãã¼ã¿ã¹ã³ã¼ã404 㧠空æååãè¿ããããªã®ã§ãAPIå®è¡å¤±ææã®ãã¹ãã®ããã«ç©ºã®ãã¡ã¤ã« hogehogehoge.json ãç¨æããã
ãã¹ããæ¸ãã¨ãã¼ã£ã¨ãããªæãã«ãªã£ãã
setUpClass ã¡ã½ããã§ã¯Stubãµã¼ãã®ãã¼ãçªå·ãæå®ãããããµã¼ãã®ã¤ã³ã¹ã¿ã³ã¹ãä½ã£ã¦èµ·åããããã¦ãããä»å㯠12345 㧠Stubãµã¼ããèµ·åããããã«ãã¦ããããµã¼ã㯠tearDownClass ã¡ã½ããã§åæ¢ããã
setUp ã¡ã½ããã§ã²ã¨ã¤ã®ãã¹ããèµ°ããã³ã« Stub ãµã¼ãããããã«ãã¦ãããStub ãµã¼ãã«ã¯ãµã¼ãã«è¿ãã¦ã»ããã¬ã¹ãã³ã¹ããã¹ãã®æåã§ã²ã¨ã¤ã²ã¨ã¤ç»é²ããä»çµã¿ã«ãªã£ã¦ãããããã§ç»é²ããã¬ã¹ãã³ã¹ãå ¨ã¦è¿ãããããã«ãã¹ããæ¸ããªãã¨ãããªããããç»é²ããã¬ã¹ãã³ã¹ãè¿ããã«æ®ã£ã¦ããããã¹ã失æã¨ã¿ãªããtearDown ã¡ã½ããã§ãããç£è¦ãã¦ããã
testProfileAPISuccess ã¡ã½ãã㨠testProfileAPIFailure ã¡ã½ãããå®ç¾©ããProfile API ãæåããæã¨å¤±æããæã®ãã¹ããæ¸ããã
ãã£ãä¿åãã JSON ãã¡ã¤ã«ãã NSData ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãä½ããStub ãµã¼ãã« Stub ã追å ãããããã§è¨å®ãããã¹ã«ãªã¯ã¨ã¹ãããã£ãã¨ãããã¡ã¤ã«ã®å 容ãã¯ã©ã¤ã¢ã³ãã«è¿ãããã«ãªããandJSONResponse ã¡ã½ãã㧠JSON ã®ãã¼ã¿ãæå®ãã㨠Content-Type ã« application/json ãå«ãã¦ããããã¾ãã¹ãã¼ã¿ã¹ã³ã¼ããæå®ãããã¨ãã§ããã
å®è£ ãã CoderwallAPIClient 㯠AFHTTPClient ã¯ã©ã¹ã®ãµãã¯ã©ã¹ãªã®ã§ãclientWithBaseURL: ã¡ã½ãã㧠Stub ãµã¼ãã«ã¢ã¯ã»ã¹ããããã«æå®ãã¦ãããã°ãå®éã®ã¢ããªã±ã¼ã·ã§ã³ã¨åãã¯ã©ã¤ã¢ã³ãã使ã£ã¦ãã¹ããã§ããããã¨ã¯ API ãå®è¡ããå¾ã«ãã¹ãå¦çãæ¸ãã¦ããã¨ããã§ãã¯ã©ã¤ã¢ã³ããæ£ããæ©è½ãã¦ãããã©ããã®ãã¹ããæ¸ãã¦ããã°ããã
ä½ã£ã coderwall ã® API ã¯ã©ã¤ã¢ã³ã㯠https://github.com/slightair/coderwallAPIClient ã«ç½®ãã¦ããã¾ãã