id:goyoki ããã®æ¬¡ã«ãªãTDD Advent Calendar jp: 2011ã®9æ¥ç®ã§ãã
ã¾ã£ããèªéããªãç´ æµã¨ã³ããªãç¶ãã¦ããã®ã§ããããã§æ¯æãããã¾ãããã
TDD ã«ã¤ãã¦ã®çè«ãæ ç·ãå®è·µã«ã¤ãã¦ã¯ãã§ã«èªããã¦ãã¾ã£ãã®ã§ãç¾å ´ã§ä½¿ããã話ãæ¸ãããã¨æãã¾ãã
åæ
ãã®ã話㯠ãã£ã¯ã·ã§ã³ ã§ãã
ç¾å®ã«ããä¼¼ãå
æ¯ãè¦ããèãããããã¨ãã¦ããããã¯å¹»æ³ã§ããå¹»æ³ã®ã¯ãã§ããå¹»æ³ã¨ãããã¨ã«ãã¦ãã ãããé¡ããã¾ãã
ã¯ããã«
ããã«ã¯ C è¨èªã®ã·ã¹ãã ãããã¾ããã
è¦æ¨¡ã«ãã¦æ°ä¸è¡ã®ä¸è¦æ¨¡ãªã·ã¹ãã ã
24æé365æ¥åãç¶ãããã¨ãè¦æ±ããããã®ã§ãåã®ä»äºã¯ããã®ã·ã¹ãã ã®ä¸æ¢é¨ããã¾ããã¨æ¹ä¿®ãããã¨ã§ããã
ãã¹ãã³ã¼ãã¯ãããã®ã®ãè¨è¨ã«å¤§ããªå¤æ´ãå
¥ãåã®ãããã¯ãã³ã¼ãã対象ã¨ãªã£ã¦ãã¦ãã¦ã¼ãã£ãªãã£é¢æ°ä»¥å¤ã®ãã¹ãã¯å
¨æ»
ã¨ãããã¾ãã«ç¼ãéåã¨ãå¼ã¹ãå
æ¯ã§ããã
ã¢ãµã¼ã·ã§ã³ã®ç¡ãããã åããã ãã®ãã¹ãã³ã¼ããªã©ããããããã¦ãã¾ããã
åæè¨è¨ãæ å½ããæ¹ã¯éæ³ä½¿ãã¨è¨ã£ã¦å·®ãæ¯ãã®ãªããããã®ã¹ã¼ãã¼ããã«ã¼ã ã£ãã®ã§ããããããããæ°ã¾ããã§ããã§ã«ãªãªã¼ã¹ãããã·ã¹ãã ã«ã¯ãã¾ãèå³ããæã¡ã§ãªãæ§åã
åã¯æåã«ããã®ç°å¢ã§ãããã¯ãã³ã¼ãã®æ¹ä¿®ãæãããªãããã«ã¯ã©ããããããã ãããï¼ãã¨ããåããèªåã«æãããã¾ããã
çµæ§ããããªãã¨ãèããã¤ããã§ããã
ããããããããç¥èã¯ãã£ã¦ããå¿ç¨åãå§åçã«ä¸è¶³ãã¦ããææã ã£ãã®ã§ãåºã¦ããçãã¯å²ã¨æ®éãªãã¨ã§ããã
- ç¼ãéåãå°ãªãããã¦èåã«å¤ãã
- å¤ããè¦ãã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ãã¹ããèªååãã
ä»å㯠TDDAdventjp ãªã®ã§ããç¼ãéåãå°ãªãããã¦èåã«å¤ããããã¨ã§ãã·ã¹ãã ã®æ¹ä¿®ã TDD ã§è¡ãããã¨ããã話ãç¶ãã¾ãã
åå£èª¿æ»1
ãã¨ãç¼ãéåã¨è¨ãã©ãããã¹ãã³ã¼ãããããã ãããããã¯ã©ããã£ã¦å®è¡ãããã®ãªã®ã調ã¹ã¦ã¿ã価å¤ã¯ããã¾ãã
ãã§ã«åå¨ãã¦ãããã®ãã¨ããæå³ã§ãèªåã¯ãããåå£èª¿æ»ã¨ããã¿ã¹ã¯ã«ãã¾ããã
åã®ç°å¢ã§ã¯ãã½ã¼ã¹ããªã¼ãã¢ã¸ã¥ã¼ã«(å®è¡ãã¡ã¤ã«ãã©ã¤ãã©ãª)ãã¨ã«å¥ã
ã®ãã£ã¬ã¯ããªã¨ããæ§æã«ãªã£ã¦ãã¦ããã¹ãã¯ããããã®ãã£ã¬ã¯ããªã§ make test
ãå®è¡ããã°èµ°ãããã«ãªã£ã¦ãã¾ããã
ããã¯å¥åã§ããã
èªååã®ããã®åºç¤ããã£ãããã§ãã
ã¨ããããã«ã¼ããã£ã¬ã¯ããªã« Makefile
ãç½®ãã¦ãã«ã¼ããã£ã¬ã¯ããªã§ make test
ãããã°å
¨ã¦ã®ãã¹ããèµ°ãããã«ãã¾ããã
ããã§å
¨ã¢ã¸ã¥ã¼ã«ã®ãã¹ããä¸åº¦ã«å®è¡ã§ããããã«ãªãã¾ããã
åå£èª¿æ»2
ããã«ãã¹ãã³ã¼ãã®è§£æãé²ãã¾ããã
æ¹ä¿®å¯¾è±¡ã®ã¢ã¸ã¥ã¼ã«ã¯ãé¢æ°ãã¤ã³ã¿é
åã«ããã¤ãã³ãé§åãªã¢ã¼ããã¯ãã£ã§ãæ¥åãã¸ãã¯ã¯ã¤ãã³ããã³ãã©ã¨ãã¦å®è£
ãããã¨ã«ãªã£ã¦ããããã¹ãã³ã¼ãã¯ã¤ãã³ããã³ãã©ã¨ä¸å¯¾ä¸ã«å¯¾å¿ãã¦ãã¾ããã
ã¦ã¼ãã£ãªãã£é¢æ°ã¯åºæ¬çã« static
宣è¨ããã¦ãããå¤é¨ã«ã¯è¦ããªãæ¹éã®ããã§ããã
ãªãããã¹ãã³ã¼ãã®ææãã¾ã¨ãã¦ã¿ãã¨ãããªæãã§ãã
- ããããã®ãã¹ãã³ã¼ãã«ãåãååã®å¤æ°ãé¢æ°ãå®ç¾©ããã¦ãã
- ã°ãã¼ãã«å¤æ° (ãã¬ã¬)
- å ±éã©ã¤ãã©ãªé¢æ° (ã¹ã¿ãé¢æ°ã¨ãã¦æ¯ãèããå¶å¾¡ã§ããã®ã§ããã¯ããã£ãã®ããª)
- ãã¹ãã©ã³ãã¼ã¨ãªãã¢ã¸ã¥ã¼ã«ãç¡ã
ãããªæãã§ããã
åé¡ã¯è¦ã¦åããã¨ãã次㮠2 ç¹ã
- ã°ãã¼ãã«å¤æ°é åã¨ã¹ã¿ãé¢æ°é åã®å 容ããã»ã¨ãã©ã®ãã¹ãã³ã¼ãã§éè¤ãã¦ã
- ãã¹ãé¢æ°ã®é åãå¿ ç¶çã«ä¸ã®ã»ãã«éã¾ã£ã¦ããã®ã§èªãã®ãé¢å
æ§æãç¶æããã¾ã¾ãã¹ãé¢æ°ãå å®ãããã¹ããã0 ããæ¸ãç´ãã¹ãããçµæ§æ©ã¿ã¾ããã
ãã¹ãã³ã¼ãã®çµç¹å
ã¦ã¼ãã£ãªãã£é¢æ°ã®ãã¹ãã³ã¼ã
æ¯è¼çç¬ç«ãã¦ããã¦ã¼ãã£ãªãã£é¢æ°ã®ãã¹ãã³ã¼ãã«ã¤ãã¦ã¯ãå ±éããé¨åãã¾ã¨ãã¦ãåºåºã¯ã©ã¹ã®ããã«æ±ããã¨ã«ãã¾ããã
ã¦ã¼ãã£ãªãã£é¢æ°ã«ã¯ãå ¥åå¤ã«å¯¾ãã20以ä¸ã®ãã§ãã¯ãå«ãé¢æ°ããã£ããããã®ã§ããã¹ãã³ã¼ãã«éä¸ã§ããããã«ãªã£ã¦ããã£ãã¨æãã¾ãã
ã¤ãã³ããã³ãã©ã®ãã¹ãã³ã¼ã
å
é¨ç¶æ
(ãã¡ããã°ãã¼ãã«å¤æ°)ã«ãã£ã¦åç
§ããã¤ãã³ããããªã¯ã¹ãæ¿ããããã«ãªã£ã¦ãããããã¤ãã³ããã³ãã©ã®ãã¹ãã¨ãã¦ãæ¯ãèãã®æ¤è¨¼ã¨ãå
é¨ç¶æ
(äºåã»äºå¾)ã®æ¤è¨¼ãå¿
è¦ã«ãªãã¾ãã
ããããæ®å¿µãªããæ¢åã®ãã¹ãã³ã¼ãã§ã¯ãã¤ãã³ããã³ãã©ã®è¿ãå¤ã ãããæ¤è¨¼ãã¦ãã¾ããã§ãããããã§ã¯ãã¹ãã«ãªã£ã¦ãã¾ããã
æ¯ãèãã®æ¤è¨¼
æ¯ãèããæ¤è¨¼ããããã«ãã¹ã¿ãé¢æ°ãæ´»ç¨ãã¾ããã
é¢æ°å¼ã³åºãã®å¼æ°ãè¨é²ãããè¿ãå¤ãè¨å®ã§ããããã«ãããã¨ãã£ããã¨ã§ãã
å¾ã§ãââã®é¢æ°ãå¼ã°ãã¦ãããã¨ãã¿ãããªãã¹ãé
ç®ãæ½åºããã®ã«ãå©ç¨ã§ãã¾ããã
å é¨ç¶æ ã®æ¤è¨¼
2 éã3 éã®ãããªã¯ã¹ãããªãå
é¨ç¶æ
ã®ãããæã§æ¸ãã®ã¯æåãã諦ãã¦ã¾ããã
代ããã«ãxls ã«æ¸ããã¦ããã¤ãã³ããããªã¯ã¹ã Ruby ã§ãã«ããã«ããã¦ãæãå¾ãçµã¿åããã®ãã¹ãé¢æ°ãå
¨é¨çæãã¦ã¿ããã2000 ãè¶ãã¾ããã
å®è¡ã«ãããæéã¯ããã§ããªãã®ã§ãã¾ããããããªãã
ãã㦠TDD ãã¡ãã£ã¨ã ã
ãã£ã¨ããæ¬é¡ã® TDD ã§ãã
ä»æ§ã¯ãã決ãããã¦ãã¾ã£ã¦ããããã³ã¼ãã£ã³ã°è¦ç´ã«ãã£ã¦ãªãã¡ã¯ã¿ãªã³ã°ãã§ããªãããã¸ã§ã¯ãã ã£ãã®ã§ãæè©®ã¯ä¼¼é TDD ã§ããã
ã¾ãããã¹ãçµæã®åºåã«è²ãä»ãããã¨ã«ãã¾ããã失æã¯èµ¤ãæåã¯ç·ã
å¶å¾¡ã³ã¼ããé§ä½¿ãã¦èæ¯è²ãå¤ããã¨ãããã¤ã§ãã ^[[32m]
ã¨ã ^[[0m]
ã¨ãã§ããããããã¾ããããã§ããããªãã®ãããªãã£ããã§ããã
次ã«ãã¹ãã©ã³ãã¼ã®ã³ã¼ãã« SEGV ãæ¡ãæ½°ãã·ã°ãã«ãã³ãã©ãå®ç¾©ãã¾ããã
ãã¹ããå®è¡ããããã¨ããããæå¾ã¾ã§èµ°ã£ã¦ã»ããã£ãããã§ããä¾å¤ãã£ããã¨ãé«åº¦ãªæ©è½ã¯ç¡ãã®ã§é«ç´è¨èªç¾¨ãããªã¼ã¨ãæã£ã¦ã¾ããã
ã¨ããããããã ãã®æºå㧠TDD ãå§ãã¦ã¿ã¾ããã
ãã£ã±ãäºåã®è¨è¨éãã«ãã¹ãããæ¸ãã¦ã¿ãã¨ãã©ãã«ããã¾ããããªãã±ã¼ã¹ãããã¾ããã
ãããããã TDD ã®å¹æãããªã©ã¨æ¯è¨ãè¨ããªãããå
ã®å
é¨ç¶æ
ã«ã¶ãä¸ããå½¢ã§ããã«å
é¨ç¶æ
ã追å ããããè¨è¨ãå¤æ´ãã¦(ãã¡ãããã¹ãã³ã¼ããçæããªããã¦)ããªãã¨ããã¹ãã¯éãããã«ãªãã¾ããã
ã¡ãªã¿ã«ãã客æ§ã«å¯¾ãã¦ã¯ã詳細è¨è¨æ¸ã¯ Doxygen ã§çæãããã®ã¨ãããã¨ããåæãå¾ã¦ããã®ã§åºæ¥ããã¨ã§ããã
ããã詳細è¨è¨æ¸ã¨ãã¦ãããã¼ãã£ã¼ããç¶æ
é·ç§»å³ãè¦æ±ããã¦ãããæéçã«ã¢ã¦ãã§ãããã
ãã¹ããã¡ããã¨æ¸ãããã¨ã®å¹æã¯å²ã¨ãã£ãããã§ããã®å¾ã®çµå試é¨ã«ããã¦ãç¶æ ç°å¸¸ã¨ãªããããªåé¡ã¯çºçãã¾ããã§ãããããã¯å¬ãããã¨ã§ããã(ãã®ä»£ããã«ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ä»æ§ãã°ãã¼ãã¼ãåºã¾ãã orz)
ã·ã¹ãã ã®å¼ãç¶ã
åãæ¸ãã¦ããã·ã¹ãã ã®æ¹ä¿®ãå¥ã®äººã«ä»»ãããã¨ã«ãªã£ãã¨ãããå¼ãç¶ãã¨ç§°ãã¦æ¬¡ã®ãããªæéãåãã¾ããã
- ãã¹ãã³ã¼ããéããããã°ã©ã ã®å é¨åä½ã®èª¬æ
- ãã¹ããæ¸ããå®è£ ããããåé¡ãããã°ããã確ããããã¹ããæ¸ããã¨ããããæ¹ã®èª¬æ
ããã¹ãã失æããã¨èµ¤ããªããæåããã¨ç·ã«ãªããã¨ããã®ã¯ãããã°ã©ãã³ã°ã«ä¸æ £ããªäººã«ã¨ã£ã¦ããè¦è¦çãªå°è±¡ã¨å ±ã«ã¢ããã¼ã·ã§ã³ãç¶æãããããã¼ã«ã ã£ãããã§ãã
å¼ãç¶ãã 人ãå¥ã®å ´æã§æ¸ãã¦ããæç« ã«ãããã¹ããå ¨é¨æåãã¦ç·ã«ãªã£ãæã¯éææãããã¾ããããªã©ã¨ãã£ã¦ãèªåã®è¦å´ã¯ç¡é§ãããªãã£ãã®ããªãã¨å°ãæãç´ãã¾ããã
æå¾ã«
ä¸è¿°ã®ã¨ãããããç¨åº¦ã®èªååãããã¦ããããã¹ããæ´åãããã¨ã§ãç¼ãéåã¯ä»ã§ã¯å°ãå¹²ããã³ãèçç¨åº¦ã«ã¾ã§å復ãã¾ããã
ããããå
é¨å®è£
ã«ä¾åãããããã¹ãã³ã¼ããå¤ã
ããããããªãã¡ã¯ã¿ãªã³ã°ãè¡ãåã«ãã¹ãã³ã¼ãèªä½ã®è¦ç´ããå¿
è¦ã§ãã
åã¯è«¸äºæ
ã«ããããã¸ã§ã¯ããé¢ãããã¨ã«ãªã£ã¦ãã¾ãããé¢ãããªãã®ã§ããã®ç¹ã ããå¿æ®ãã§ãã
xUTP読書会ã«åå ãã¦ãæ§ã ãªæ¹ã ã«æãã¦ããã ããããããããããã£ããã¨ãèããããããã«ãªã£ãã®ã ã¨æã£ã¦ãã¾ããä¼ç¤¾ã®ä¸ã ãã§ã¯çµ¶å¯¾ã«ä»ã®èªåã¯åå¨ãã¦ãã¾ããã§ãããæ¬å½ã«æè¬ãã¦ãã¾ãã
ãã¾ã
ç§ãèªåã® TDD ãèªããã¨ãã§ããããã«ãªãã¾ã§å¦ã¶ãã¨ã¯å¤ãããããå¾
ã£ã¦ããéã«äººçãçµãã£ã¦ãã¾ãã¾ãã
ããã§ãèªåã®å¦ã³ãç¥èã®æºæ³ã¨ãªã£ã xUTP ã®ã¨ãã»ã³ã¹ãåºãä¼ãããããxUTP読書会ã®æå¿ã¨å
±ã« Web ãã¬ã¸ã³ぺけまãå§ãã¾ããã
TDD ãå§ãã¦ã¿ã人ããã¬ã¬ã·ã¼ã³ã¼ãã«ç«ã¡åãã人ã«ã¨ã£ã¦ãå°ãã§ãå©ãã«ãªãã°å¹¸ãã§ãã
ãªãããºãã¾èªä½ãç¶ãã¦ããã®ã大å¤ãªã®ã§ãååè
ã¯ãã¤ã§ãåéä¸ã§ãã
æ¬å½ã«æå¾ã«
ææ¥ã¯ TDDBC åé¸ã®ä¸»å¬è
ã§ãä»ã¯æ±äº¬ä½ã¾ã㪠id:katzchang ããã®VOYAGE GROUP エンジニアブログ : 滅びの言葉をテストするã§ãã
ç´ æ´ããé ã®åããæ¹ãªã®ã§ãåãå³éãã¨ã³ããªãæå¾
ãã¦ãã¾ãï¼