å±¥æŽïŒãã®èšäºã¯2006幎3æã«Better Softwareèªã«åããŠæ²èŒãããŸãããè€æ°ã®èšèªã«ç¿»èš³ãããŠããŸããããæ¥ãç§ã¯åé¡ã«ééããŸããã éçºè
ã«ããŸããŸãªãããžã§ã¯ãã®TDDãªã©ã®ã¢ãžã£ã€ã«ããã°ã©ãã³ã°ãã©ã¯ãã£ã¹ãæãããšããã°ãã°æ··ä¹±ãšæ··ä¹±ã«ééããŸããã 圌ãã¯ãã©ãããå§ããŠãäœããã¹ãããäœããã¹ãããªãããäžåºŠã«ã©ãã ããã¹ããããããã¹ãã«ååãä»ããæ¹æ³ããã¹ãã倱æããçç±ãç解ããæ¹æ³ãç¥ãããã£ãã®ã§ãã
TDDã䜿çšããã°ããã»ã©ãèªåã®ã¹ãã«ã磚ãäžããæ°ããé«ã¿ã«å°éããã®ã§ã¯ãªãããã©ã€ã³ããžã®åãã§ããããšã«æ°ä»ããŸããã ãããããã誰ããããã以åã«ç§ã«èšã£ãŠãããªãïŒããšããèãããããç§ãããé »ç¹ã«æãã€ããããšãèŠããŠããŸãããçŽ æŽããããéã¯æ確ã§ããã TDDããã¬ãŒãã³ã°ããæ¹æ³ãèŠã€ããå¿
èŠããããšå€æããŸãããTDDãããã«ããšã©ãŒãªãæ£ããæäœããæ¹æ³ã瀺ããŸããã
ãããŠããã®æ¹æ³ã¯æ¯ãèããéããŠããã°ã©ãã³ã°ããŠããŸãã ã¢ãžã£ã€ã«ãã©ã¯ãã£ã¹ããçãŸãããã®ã§ã銎æã¿ã®ãªãããŒã ã«ãšã£ãŠãã¢ã¯ã»ã¹ããããå¹æçãªãã®ã«ãªãããã«èšèšãããŠããŸãã æéãçµã€ã«ã€ããŠãBDDã«ã¯ã¢ãžã£ã€ã«åæãšèªååãå
¥ãïŒ
ãããåãå
¥ãïŒãã¹ããå«ãŸããããã«ãªããŸããã
ãã¹ãïŒã¡ãœããïŒã®ååãæç« ã§è¡šçŸãã
ç§ã®çºèŠãåã³ã«æºã¡ããAhaïŒãã¯ãååã®ã¯ãªã¹ã»ã¹ãã£ãŒãã³ãœã³ã«ãã£ãŠæžããã
äžèŠã·ã³ãã«ãªãŠãŒãã£ãªãã£
agiledoxãèŠãããããšãã«æããŸããã 圌女ã¯JUnitãã¹ããå«ãã¯ã©ã¹ãåãããã®ååãç°¡åãªæã®åœ¢åŒã§åºåããŸãã ãã®ããããã¹ãã±ãŒã¹ã¯æ¬¡ã®ããã«ãªããŸããã
public class CustomerLookupTest extends TestCase { testFindsCustomerById() { ... } testFailsForDuplicateCustomers() { ... } ... }
次ã®ããã«åºåãããŸãã
CustomerLookup
- IDã§é¡§å®¢ãèŠã€ãã
- éè€ãã顧客ã«å¯ŸããŠå€±æãã
- ...
ïŒæ³šãCustomerLookup [顧客æ€çŽ¢]ïŒIDã§é¡§å®¢ãèŠã€ããŸãã顧客ãç¹°ãè¿ããããšããããããŸããïŒããã¹ãããšããåèªã¯ã¯ã©ã¹åãšã¡ãœããããåé€ãããã©ã¯ãåã¬ã³ãŒãã¯ãã¬ãŒã³ããã¹ãã«å€æãããŸãã 圌女ã¯ããã§ãã¹ãŠã§ãããå¹æã¯é©ãã¹ããã®ã§ãã
éçºè
ã¯ããã®æ¹æ³ã§ããã¥ã¡ã³ãã®å°ãªããšãäžéšãèªåçšã«äœæã§ããããšã«æ°ã¥ãããã¹ãã®ååãæã®åœ¢ã§æžãçããããã«ãªããŸããã ããã«ãããžãã¹ãã¡ã€ã³ã®èªåœã䜿çšããŠã¡ãœããåãã€ã¥ããšãçæãããããã¥ã¡ã³ããããžãã¹ãŠãŒã¶ãŒãã¢ããªã¹ãããã¹ã¿ãŒã«ââç解ã§ããããšãããããŸããã
ééããªãããã®ç°¡åãªãã¹ãæäŸãã³ãã¬ãŒãã䜿çšããŠãã ããã
ãã®åŸãèå³æ·±ãæãã³ãã¬ãŒããèŠã€ããŸãããããã«ããã°ããã¹ãŠã®ãã¹ãåã¯åèª
will ïŒ
ããã ShouldïŒã§å§ãŸãå¿
èŠããããŸãã ãã®æ-
ãã®ã¯ã©ã¹ã¯äœããããå¿
èŠããããŸã ïŒ
ããããã®ã¯ã©ã¹ã¯äœã
ãããŸãïŒ-çŸåšã®ã¯ã©ã¹ã«å¯ŸããŠã®ã¿ãã¹ããæžãããšãã§ããããšã瀺åããŠããŸãã ã ãããããªãã¯ééããããªãã§ãããã ãã®ããã«è¡šçŸã§ããªããã¹ããäœæããããšããŠããããšãããã£ãå Žåãæããã«ããã¯å¥ã®ãªããžã§ã¯ãã®åäœã§ãã
ããšãã°ãäžåºŠãç»é¢ããã®å
¥åããã§ãã¯ããã¯ã©ã¹ãäœæããŸãã ã»ãšãã©ã®ãã£ãŒã«ãã¯ãéåžžã®é¡§å®¢ã®è©³çŽ°ã§ãïŒåãå§ãªã©ã ãããããã®åŸãç幎ææ¥ã®ãã£ãŒã«ããšå¹Žéœ¢ã®ãã£ãŒã«ãããããŸããã ãtestShouldFailForMissingSurnameãïŒå§ããªãå Žå
ã¯ãã¹ãã倱æããããšã«
泚æããŠãã ãã ïŒããtestShouldFailForMissingTitleãïŒã¿ã€ãã«ããªãå Žå
ã¯ãã¹ãã倱æããããšã«
泚æããŠãã ããïŒãªã©ã®ã¡ãœããã䜿çšããŠããClientDetailsValidatorTestãïŒã¯ã©ã€ã¢ã³ãã®è©³çŽ°ã®ããªããŒã¿ãŒã«
泚æ ïŒãæžãå§ããŸããã
ããããç§ã¯å¹Žéœ¢ã®èšç®ã«å°æããæ··ä¹±ããããžãã¹ã«ãŒã«ã®äžçã«æ²¡é ããŸããïŒç幎ææ¥ãšå¹Žéœ¢ããããããããäžèŽããªãå Žåã¯ã©ããªããŸããïŒ èªçæ¥ãä»æ¥ã®å Žåã¯ã©ããªããŸããïŒ ç§ãããå Žåãç幎ææ¥ã¯äœæ³ã§ããïŒ ãã®åŸããã®åäœã説æããããã«é·ããã¹ãåãæžãå§ããŸããããåæ¢ããŠãã¹ãŠã移åããããšã«ããŸããã ããã§ããAgeCalculatorTestãïŒå¹Žéœ¢èšç®æ©ã®
ãããã®ãã¹ãïŒã§ãAgeCalculatorãïŒ
ããã幎霢èšç®æ©ïŒãšããã¯ã©ã¹ãäœæããŸããã ãããã£ãŠã幎霢ãèšç®ããããã®ãªããžã§ã¯ãã®åäœå
šäœããã®èšç®æ©ã«ç§»åãããClientDetailsValidatorãã¯é¢é£ãããã¹ãã1ã€ã ãå¿
èŠãšããŸãã-幎霢èšç®æ©ãšã®æ£ããçžäºäœçšã確èªããŸãã
ã¯ã©ã¹ã1ã€ä»¥å€ã®äœããè¡ãå Žåãããã¯éåžžããã®ä»ã®ã¯ã©ã¹ãããã«äœæããå¿
èŠãããããšã瀺ããŠããŸãã ç§
ã¯ãããäœããã
ããèšè¿°ããã€ã³ã¿ãŒãã§ãŒã¹ã®åœ¢ã§æ°ãããµãŒãã¹ãäœæããããããã¡ãŒã¹ãã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ãŒã«æž¡ããŸãïŒ
public class ClientDetailsValidator { private final AgeCalculator ageCalc; public ClientDetailsValidator(AgeCalculator ageCalc) { this.ageCalc = ageCalc; } }
äŸåæ§æ³šå
¥ãšåŒã°ãããªããžã§ã¯ããäžç·ã«äœæãããã®ã¹ã¿ã€ã«ã¯ãã¢ãã¯ãªããžã§ã¯ãã§ç¹ã«åœ¹ç«ã¡ãŸãã
ãã¹ãã«æ確ãªååãä»ããŠãã ããïŒãã¹ããèœã¡ããšãã«å©ããŠ
ãã°ããããŠãã³ãŒããå€æŽããŠãã¹ããç Žãããšã§ãã³ãŒãã®äºæ³ãããåäœãååã§æ確ã«ç解ã§ããããšãããããŸããã éåžžã次ã®3ã€ã®ãããããçºçããŸããã
- ééã£ãã³ãŒããæžããŸããã æªãã 解決çïŒã³ãŒããä¿®æ£ããŸãã
- åäœã¯éèŠã§ããããã©ããã«ç§»åããŸããã 解決çïŒãã¹ãã移åããå Žåã«ãã£ãŠã¯å€æŽããŸãã
- åäœãtrueã§ãªããªã£ãïŒã·ã¹ãã ã®ã¿ã¹ã¯ãå€æŽãããŸããã 解決çïŒ ãã®ãã¹ããåé€ããŸã ã
åŸè
ã¯ãç解ã®åäžãšãšãã«ãã¢ãžã£ã€ã«ãããžã§ã¯ãã§ãã°ãã°çºçããŸãã æ®å¿µãªãããTDDã®åå¿è
ã¯ãã¹ããåé€ãããšããå
倩çãªæãããããŸããããã¯ã³ãŒãã®å質ãäœããã®åœ¢ã§äœäžããããã®ããã§ãã
åèªã®ããç®ç«ããªãè²åãã¯ãããæ£åŒãªä»£æ¿
åè£ ïŒ
ããã WillãŸãã¯shouldïŒãšæ¯èŒãããšãç解ã§ããããã«ãªããŸãïŒ
ããã ShouldïŒã
ãã㯠ããã¹ãã®åäœãçãããšãã§ãã
ããšãæå³ããŸããã圌ã¯æ¬åœã«ãããè¡ãã®ã§ããããïŒãããã«ãããã³ãŒãå
ã®ãšã©ãŒã«ãã£ãŠãã¹ããå®éã«ã¯ã©ãã·ã¥ããç¶æ³ãšãã·ã¹ãã ã®åäœã«é¢ããããªãã®èãããã§ã«ééã£ãŠããç¶æ³ãšãåºå¥ãããããªããŸãã
ããã¹ããã§ã¯ãªããè¡åããšããèšèã䜿çšãã
ããã§ããtestããšããåèªãåé€ããŠããã¹ãã®ååããšã«ãã®æã䜿çšããããã®ããŒã«-agiledoxãã§ããŸããã ããããç§ã¯ãTDDãå匷ãããšãã人ã
ã¯ã»ãšãã©åžžã«ããã¹ãããšããèšèã«ã€ãŸããããšã«æ°ä»ããŸããã
ãã¡ããããã¹ããTDDã«åºæã§ã¯ãªããšããã®ã¯äºå®ã§ã¯ãããŸãããã¡ãœããã®æçµã»ããã¯ãã³ãŒããæ©èœããŠããããšã確èªããããã®è¯ãæ¹æ³ã§ãã ãã ãããã¹ãã§ã·ã¹ãã ã®åäœãå®å
šã«èšè¿°ãããŠããªãå Žåã¯ã誀ã£ãã»ãã¥ãªãã£æèŠã§ã ãŸãããŸãã
TDDã䜿çšããŠãããšããããã¹ãããšããèšèã®ä»£ããã«ãè¡åããšããèšèã䜿çšãå§ããŸããããããé©åã§ããã ãã§ãªããåŠçããã®è³ªåã¯ãã¹ãŠéæ³ã®ããã«æ¶ããŠããŸããŸããã ä»ãç§ã¯ãããã®TDDã®è³ªåã®ããã€ãã«çããŸããã ãã¹ãã«ååãä»ããæãç°¡åãªæ¹æ³ã¯äœã§ããïŒ -ããã¯ã次ã®èå³æ·±ãåäœã説æããæã§ãã åé¡ã¯ã詳现ã«ãã¹ãããæ¹æ³ã§ããïŒ çŽç²ã«çè«çã«ãªããŸãïŒæãèš±ãéãã®åäœã®ã¿ãèšè¿°ã§ããŸãã ãã¹ãã倱æããå Žåã®å¯ŸåŠæ¹æ³ -äžèšã®æé ã«åŸã£ãŠãã ããïŒãã°ãäœæããããåäœã移åãããããã¹ããäžèŠã«ãªããŸããã
ãã¹ããããè¡åã§èããããšã¯éåžžã«æçã§ããããšãããã£ãã®ã§ãè¡åãŸãã¯BDDãä»ããŠTDDãã¹ããšåŒã³å§ããŸããã
JBehaveã¯ãã¹ãã§ã¯ãªãåäœã«çŠç¹ãåœãŠãŠããŸã
2003幎ã®çµããã«åãã£ãŠãç§ã¯ä»è©±ããŠããããšã«ãéãããããã¯å°ãªããšãç§ã®æéãæè³ããæã§ãããšæ±ºããŸããã JUnit-JBehaveã«ä»£ãããã®ãæžãå§ããŸããã ãã®äžã«ãã¹ããžã®èšåã¯ãããŸããã§ãã;圌ã¯ãã¹ããããæ¯ãèããäžå¿ã«æ§ç¯ãããèªåœã«çœ®ãæããŸããã ãã®ãã¹ãŠã¯ãåäœãä»ãããã¹ãã«é¢ããæ°ãããã³ãã©ãå³å¯ã«éµå®ããå Žåã«ããã®ãããªãã¬ãŒã ã¯ãŒã¯ãã©ã®ããã«é²åãããã調ã¹ãããã§ãã ãŸãããã®ããŒã«ã¯ãåèªãã¹ããã掟çããåèªã®æ³šæããããããšãªãTDDãšBDDãæããã®ã«åœ¹ç«ã€ãšæããŸããã
æ¶ç©ºã®ãCustomerLookupãïŒ
ãããã®é¡§å®¢æ€çŽ¢ïŒã¯ã©ã¹ã®åäœãå®çŸ©ããã«ã¯ãããšãã°ãCustomerLookupBehaviorãïŒ
ãããã®é¡§å®¢æ€çŽ¢åäœïŒãšåŒã°ããåäœã®ã¯ã©ã¹ãäœæããŸãã ãwillããšããåèªã§å§ãŸãã¡ãœãããå«ãŸããŸãïŒ
泚æãå¿
èŠã§ãïŒã JUnitããã¹ãçšã«è¡ãããã«ãåäœãã§ãã¯ïŒ
ãããåäœã©ã³ããŒïŒãéå§ããããã°ã©ã ã¯ããã®åäœã¯ã©ã¹ãäœæããåäœãé çªã«èšè¿°ããåã¡ãœãããåŒã³åºããŸãã ãã®åŸã圌女ã¯åŠåã®é²è¡ç¶æ³ã«ã€ããŠå ±åããæåŸã«çµæãåºããªããã°ãªããŸããã
ç§ã®æåã®ç®æšã¯ãJBehaveã«èªåèªèº«ããã¹ããããããšã§ããã ãã®ããã°ã©ã ãããèªäœãå®è¡ã§ããããã«ããåäœãè¿œå ããŸããã ãã¹ãŠã®JUnitãã¹ããJBehaveã®åäœã«è»¢éããJUnitãšåããã£ãŒãããã¯ãåŸãããšãã§ããŸããã
次ã®æãéèŠãªåäœãç¹å®ããŸã
JBehaveã䜿çšãããããã®å®éšã®çŽåŸã«ãããžãã¹äŸ¡å€ã®æŠå¿µãç解ãå§ããŸããã ãã¡ãããç§ã¯äœãã®ããã«ã³ãŒããæžããŠããããšãåžžã«ç¥ã£ãŠããŸããããä»æžããã³ãŒãã®éèŠæ§ã«ã€ããŠã¯èããŸããã§ããã ç§ã®ååã§ããããžãã¹ã¢ããªã¹ãã®ã¯ãªã¹ãããã¯ãè¡åã«ãããã¹ãã®ã³ã³ããã¹ãã«ãããããžãã¹ã®é¢é£æ§ã«ã€ããŠèããããã«ä¿ããŸããã
ãã®ç®æšã念é ã«çœ®ããŠ-JBehaveã®ã»ã«ããã¹ããè¡ãã«ã¯ãããç°¡åã«çŠç¹ãåãããããã«ã
ãã·ã¹ãã ãå®è¡ããªã次ã®æãéèŠãªããšã¯äœã§ããïŒããã®è³ªåã§ã¯ããŸã å®è£
ããŠããªãæ©èœã®éèŠæ§ãå€æããåªå
é äœãä»ããå¿
èŠããããŸãã ãŸããæ¯ãèããèšè¿°ããã¡ãœããã®ååãå®åŒåããã®ã«åœ¹ç«ã¡ãŸããã·ã¹ãã ã¯XïŒXã¯æ確ãªæ¯ãèãã§ãïŒã§ã¯ãªããXã¯éèŠã§ãã ããã¯ãã·ã¹ãã ãXãå®è¡ããããšãæå³ããããã次ã®åäœæ¹æ³ã¯æ¬¡ã®ããã«ãªããŸãã
public void shouldDoX() {
ããã§ãTDDã«ã€ããŠã®è³ªåãã€ãŸãã©ãããå§ããã°ããã®ããšããçããåŸãããŸããã
èŠä»¶ãè¡åã§ã
ç§ã®æã«ã¯ãã¬ãŒã ã¯ãŒã¯ããããTDDã®ä»çµã¿ãç解ããããã«éèŠãªããšãšããŠãçºèŠãããã¹ãŠã®èœãšãç©Žããç§ãæã£ãã¢ãããŒãã説æããŸããã
2004幎ã®çµããé ãç§ã¯ãã€ãŠããã«å¯ŸããŠçºèŠããè¡åããŒã¹ã®ã¢ãããŒãã«ã€ããŠèª¬æãããããããããã¯ãŸãã«åæã«äŒŒãŠããŸãããšè¿°ã¹ãŸããã ãããŠãçèã®ããã«äžæåæ¢ããåŸããã®ãã¹ãŠã®è¡åããŒã¹ã®æèãé©çšããŠèŠä»¶ã決å®ããããšã«ããŸããã ãããã£ãŠãã¢ããªã¹ãããã¹ã¿ãŒãéçºè
ãããã³ããžãã¹åãã®äŸ¿å©ãªèªåœãéçºã§ããã°ãæè¡è
ãããžãã¹ã®äººã
ãšè©±ããšãã«çããäžç¢ºå®æ§ãšèª€è§£ãæé€ããããã®æ£ããéãæ©ãããšãã§ããŸãã
BDDã¯åæã®ããã®ããã¹ãŠã®èšèªã«éãããããæäŸããŸã
ãã®é ããšãªãã¯ã»ãšãŽã¡ã³ã¹ã¯ããšãªãã¯ã»ãšãŽã¡ã³ã¹ã«ãããã¹ãã»ã©ãŒã®ãã¡ã€ã³é§åèšèšãåºçããŸããã ãã®äžã§ãããžãã¹çšèªã«çŽæ¥ã³ãŒãã浞éãããããã«ãããžãã¹ã¢ãã«ã«åºã¥ããŠã誰ããã¢ã¯ã»ã¹ã§ããèšèªã䜿çšããŠã·ã¹ãã ãã¢ãã«åããæŠå¿µã«ã€ããŠèª¬æããŠããŸãã
ã¯ãªã¹ãšç§ã¯
ãåæããã»ã¹èªäœã®ããã«èª°ããã¢ã¯ã»ã¹ã§ããèšèªã決å®ããããšããŠããããšã«æ°ä»ããŸããïŒ è¯ãã¹ã¿ãŒããåããŸããã äžè¬ã«ãåœç€Ÿã«ã¯ãã§ã«æ¬¡ã®ãããªãŠãŒã¶ãŒã¹ããŒãªãŒã®ãã³ãã¬ãŒãããããŸãã
[X] ãšããŠ
欲ãã [Y]
[Z]
ïŒ
çŽ Xã§ãããããYãå¿
èŠãªã®ã§ãZãã©ããªã
ãŸããã ïŒ
ããã§ãYã¯äœããã®æ©èœãZã¯ãã®æ©èœã®ã¡ãªãããŸãã¯äŸ¡å€ãXã¯ã¡ãªããã®ãã人ïŒãŸãã¯åœ¹å²ïŒã§ãã ãã®ææ¡ã®å©ç¹ã¯ãæåã®å®çŸ©ã®éã«éçºäžã®ã¹ããŒãªãŒã®éèŠæ§ãå€æããããšã匷å¶ããããšã§ãã çµå±ã®ãšãããå®éã®ããžãã¹äžã®éèŠæ§ã®æŽå²ããªãå Žåã次ã®ãããªäœäžãèµ·ãããŸããã... [ããæ©èœ]ãå¿
èŠã§ããã ãããã[ç§ã¯ããããããããã§ããã®ã§ããïŒ]ã ã ç§ãã¡ã®æ¹æ³ã«ããããããã®ããªãé£è§£ãªèŠä»¶ãæ€èšŒã®ç¯å²ãè¶
ããŠåãããšãã§ããŸãã
ãããŠæåãããMattsãšç§ã¯ããã¹ãŠã®ã¢ãžã£ã€ã«ãã¹ã¿ãŒããã§ã«ç¥ã£ãŠããããšãçºèŠããéãæ©ãã§ããŸããããŠãŒã¶ãŒã¹ããŒãªãŒã®åäœã¯åãªãåãå
¥ãåºæºã§ããã€ãŸããã·ã¹ãã ããã¹ãŠã®åãå
¥ãåºæºãæºãããŠããå Žåããã®åäœã¯çã§ãã ããã§ãªãå Žåã¯ããããã ãã®ããããŠãŒã¶ãŒã¹ããŒãªãŒãè©äŸ¡ããããã®åºæºãèšé²ããããã®ææ¡ãã³ãã¬ãŒããäœæããŸããã
ãã®ãã³ãã¬ãŒãã¯ãã¢ããªã¹ããå¶éãäžèªç¶ããæããªãçšåºŠã«ã·ã³ãã«ã§ããå¿
èŠããããŸãããã¹ããŒãªãŒãã³ã³ããŒãã³ããã©ã°ã¡ã³ãã«åå²ããŠèªååã§ããããã«é åºä»ããããŠããå¿
èŠããããŸãã ãããã£ãŠã
ã¹ã¯ãªããã®æŠå¿µã䜿çšããŠåãå
¥ãåºæºã説æããŸãããããã¯æ¬¡ã®åœ¢åŒãåããŸããã
ïŒ ãããã -äžããããïŒã³ã³ããã¹ããæã£ãŠããã
ã€ãã³ããçºçãããšã ïŒ ããã ïŒã
æ¬¡ã« ïŒ çŽ ïŒçµæã確èªããŸãã
ãããå®èšŒããããã«ãå€å
žçãªATMã®äŸã䜿çšããŸãããã ã¹ããŒãªãŒã«ãŒãã®1ã€ã¯æ¬¡ã®ããã«ãªããŸãã
+ååïŒé¡§å®¢ã¯çŸéãåŒãåºããŸã+
顧客ãšããŠ
ATMãããéãåŒãåºããã
ã§ããã ãéè¡ã§äžŠãã§åŸ
ã€å¿
èŠã¯ãããŸããã
ããŠãç©èªãçµãã£ãããšãã©ã®ããã«ç解ããŸããïŒ ããã€ãã®ã·ããªãªããããŸããå£åº§ã«ãéããããŸãã ã¢ã«ãŠã³ãã«ãéã¯ãããŸããããåœåº§åè¶å
ã§åŒãåºãããšãã§ããŸãã ã¹ã³ã¢ãåœåº§è²žè¶ãè¶
ããŸããã ãã¡ãããä»ã®ã·ããªãªããããŸãããã®åŒãåºããæ£ç¢ºã«åœåº§è²žè¶ã§ããããATMã«ãéããããŸããã
Have-When-Thenãã¿ãŒã³ã䜿çšãããšãæåã®2ã€ã®ã·ããªãªã¯æ¬¡ã®ããã«ãªããŸãã
ã·ããªãª1ïŒã¢ã«ãŠã³ãã«ãéããããŸã+
ãéã§ã¢ã«ãŠã³ããæã£ãŠãã
ãããŠæå¹ãªã«ãŒã
ãããŠçŸéä»ãATM
顧客ãçŸéãèŠæ±ãããšã
次㫠ãå£åº§ããåŒãèœãšãããããšã確èªããŸã
ãã㊠ãçŸéãçºè¡ãããŠããããšã確èªããŠãã ãã
ãã㊠ãã«ãŒããè¿ãããããšã確èªããŠãã ãã
ãŠããªã³ã䜿çšããããã€ãã®åææ¡ä»¶ïŒ
çŽæå® ïŒãšçµæïŒ
çŽæå® ïŒãçµã¿åãããããšã§ç解ã容æã«ãªãããšã«æ³šæããŠãã ããã
+ã·ããªãª2ïŒåŒãåºããåœåº§è²žè¶ãè¶
ããŠãã+
å¶éãè¶
ããã¢ã«ãŠã³ããæã£ãŠãã
ãããŠæå¹ãªã«ãŒã
顧客ãçŸéãèŠæ±ãããšã
次㫠ã倱æã¡ãã»ãŒãžã衚瀺ãããŠããããšã確èªããŸã
ãã㊠ãçŸéãçºè¡ãããŠããªãããšã確èªããŠãã ãã
ãã㊠ãã«ãŒããè¿ãããããšã確èªããŠãã ãã
äž¡æ¹ã®ã·ããªãªã¯åãã€ãã³ãã«åºã¥ããŠãããããã€ãã®äžè¬çãªããŒã¹ã©ã€ã³æ¡ä»¶ãšçµæãããããŸãã ããŒã¹ã©ã€ã³ã®æ¡ä»¶ãã€ãã³ããããã³çµæãåå©çšããããšã§ããã®æ©æµãåããããšãã§ããŸãã
åãå
¥ãåºæºãå®è¡å¯èœã«ãã
ãã®ã·ããªãªã®ãã©ã°ã¡ã³ãïŒããŒã¹ã©ã€ã³ãã€ãã³ããããã³çµæïŒã¯ãããã°ã©ã ããã®ã«ååãªã»ã©å°ãããªã£ãŠããŸãã JBehaveã«ã¯ãã¹ã¯ãªãããã©ã°ã¡ã³ããJavaã¯ã©ã¹ãšæ瀺çã«é¢é£ä»ããããšãã§ãããªããžã§ã¯ãã¢ãã«ããããŸãã
次ã®ããã«ãååææ¡ä»¶ïŒ
ããããæå®ããã ïŒãè¡šãã¯ã©ã¹ãèšè¿°ã
ãŸãã public class AccountIsInCredit implements Given { public void setup(World world) { ... } } public class CardIsValid implements Given { public void setup(World world) { ... } }
ãã®ã€ãã³ãã®1ã€ã¯æ¬¡ã®ããã«ãªããŸãã
public class CustomerRequestsCash implements Event { public void occurIn(World world) { ... } }
ã¹ã¯ãªããã®çµæã«ã€ããŠãåæ§ã§ãã JBehaveã¯ããããã¹ãŠçµã³ä»ããŠå®è¡ããŸãã ãªããžã§ã¯ããä¿åããããã®ã©ããã«ååšãããã¯ãŒã«ãããäœæããJBehaveããããååææ¡ä»¶ïŒããããïŒã«é çªã«æž¡ããæ¢ç¥ã®ç¶æ
ã§ã¯ãŒã«ããåæåã§ããããã«ããŸãã JBehaveã¯ãç¹å®ã®ã·ããªãªã®å®£èšãããåäœãå®è¡ãããã®äžçã§ã®ãçºçãã€ãã³ããèŠæ±ããŸãã ãããŠæåŸã«ãJBehaveã¯ç¹å®ã®ã¹ããŒãªãŒã§å®çŸ©ããçµæã«å¶åŸ¡ã移ããŸãã
ã¹ã¯ãªããã®åãã©ã°ã¡ã³ããè¡šãã¯ã©ã¹ã«ããããã©ã°ã¡ã³ããä»ã®ã¹ã¯ãªãããŸãã¯ã¹ããŒãªãŒã«åå©çšã§ããŸãã ãŸãããããã®ãã©ã°ã¡ã³ãã¯ãã¢ãã¯ãªããžã§ã¯ãã䜿çšããŠå®è£
ãããå£åº§ã«ãéãèšå®ããããæå¹æ§ã«ãŒããèšå®ãããããŸããããããåäœã®å®è£
ã®åºç€ãäœæããæ¹æ³ã§ãã ç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ãå®è£
ãããšãåææ¡ä»¶ãšçµæãå€ãããäœæããå®éã®ã¯ã©ã¹ã®äœ¿çšãéå§ããããããã¹ã¯ãªãããå®äºãããŸã§ã«ããããã¯æåããæåŸãŸã§çã®æ©èœãã¹ãã«ãªããŸãã
BDDã®çŸåšãšæªæ¥
ãã°ããããŠãJBehaveã¯åã³æŽ»çºã«éçºãé²ããŠããŸãã ãã®ã³ã¢ã¯éåžžã«å®æããŠãããä¿¡é Œæ§ããããŸãã 次ã®ã¹ãããã¯ãIntelliJ IDEAãEclipseãªã©ã®äžè¬çãªJava IDEãšã®çµ±åã§ãã
Dave Astelã¯æè¿BDDãç©æ¥µçã«æšé²ããŠããŸãã 圌ã®ããã°ãšããŸããŸãªåºçãããèšäºã¯ã掻çºãªæŽ»åãåŒãèµ·ãããŸããã æã泚ç®ãã¹ãã¯ãRubyã§BDDãã¬ãŒã ã¯ãŒã¯ãäœæããããã®
rspecãããžã§ã¯ãã§ãã Rubyã§JBehaveãå®è£
ããrbehaveã®äœæ¥ãéå§ããŸããã
ç§ã®ååã¯ãããŸããŸãªå®éã®ãããžã§ã¯ãã§BDDæè¡ã䜿çšããåŸããã®æ¹æ³ã倧æåã§ãããšå ±åããŸããã ã¹ããŒãªãŒãå®è¡ããããã®JBehaveãµãã«ãŒãã³ïŒåãå
¥ãåºæºã確èªããéšåïŒã¯ãç©æ¥µçã«éçºãããŠããŸãã
å°æ¥çã«ã¯ãããžãã¹ã¢ããªã¹ããšãã¹ã¿ãŒãéåžžã®ããã¹ããšãã£ã¿ãŒã§ã¹ããŒãªãŒãèšè¿°ãããã¹ãŠããžãã¹ã¢ãã«ã®èšèªã§åäœã¯ã©ã¹ã®ã¹ã¿ããªããžã§ã¯ããäœæã§ããããã«ãããã«ãµãŒã¯ã«ãšãã£ã¿ãŒãå¿
èŠã§ãã BDDã¯å€ãã®äººã
ã®å©ããåããŠé²åããŠããŸãããç§ã¯åœŒãã«æ·±ãæè¬ã®æãè¡šããŸãã
ã泚æ ãã³ããŒã¹ã¯ãã¢ãžã£ã€ã«éçºæ¹æ³è«ã®ææã§ãã ãœãããŠã§ã¢ãéçºããçŽ20幎éãããæããŸãã 圌èªèº«ã®ã³ã³ãµã«ãã£ã³ã°ããã³ãœãããŠã§ã¢éçºæ©é¢ã®äœæè
ã è¡åã«ããéçºïŒBDDïŒã®æŠå¿µãå°å
¥ããŸããã