Spring Framework㯠ãã¯ã©ãŠãã§åäœãã Twelve-Factorã¢ããªã±ãŒã·ã§ã³ ããã€ã¯ããµãŒãã¹ãããã³æãå®å®ããŠãããšåæã«é©æ°çãªè£œåã®1ã€ãéçºããããã«èšèšãããCloud Nativeãã¬ãŒã ã¯ãŒã¯ã®äŸãšããŠããåŒçšãããŸãã ãããããã®èšäºã§ã¯ãSpringã®ãã1ã€ã®åŒ·åãªåŽé¢ã«ã€ããŠèª¬æããŸããããã¯ã ãã¹ãã«ããéçºãµããŒãïŒTDDæ©èœïŒïŒã§ãã TDDã®æ¥ç¶æ§ã«ãããããããSpringãããžã§ã¯ãã¯ãã¹ãã®ãã¹ããã©ã¯ãã£ã¹ãç¡èŠããããç¬èªã®èªè»¢è»ãçºæãããããé
ãããŸãã¯ãä¿¡é Œæ§ããªãããããã¹ãããŸã£ããæžããªãããšã«ãã°ãã°æ°ä»ããŸããã ãããŠãSpring Frameworkäžã®ã¢ããªã±ãŒã·ã§ã³ã«å¯ŸããŠé«éã§ä¿¡é Œæ§ã®é«ããã¹ããäœæãããã¹ããéããŠéçºãè¡ãæ¹æ³ãæ£ç¢ºã«èª¬æããŸãã ãããã£ãŠãSpringã䜿çšããïŒãŸãã¯éå§ããïŒå Žåãäžè¬çãªãã¹ããç解ããïŒãŸãã¯ç解ããïŒãã contextLoads
ãçµ±åãã¹ãã®å¿
èŠãã€ååãªã¬ãã«ã§ãããšæããŸã-ããã¯èå³æ·±ãã§ãããïŒ
TDDã®æ©èœã¯éåžžã«ææ§ã§ããã枬å®ãå°é£ã§ãããSpringã«ã¯ãæå°éã®åŽåã§çµ±åãã¹ããšåäœãã¹ããäœæããã®ã«åœ¹ç«ã€å€ãã®æ©èœããããŸãã äŸïŒ
- çµ±åãã¹ã-ã¢ããªã±ãŒã·ã§ã³ãç°¡åã«èµ·åããããã³ã³ããŒãã³ããããã¯ãããããã©ã¡ãŒã¿ãŒãåå®çŸ©ãããã§ããŸãã
- ãã©ãŒã«ã¹çµ±åãã¹ã-ããŒã¿ãžã®ã¢ã¯ã»ã¹ã®ã¿ãWebã®ã¿ãªã©
- ããã«äœ¿ãããµããŒã-ã€ã³ã¡ã¢ãªããŒã¿ããŒã¹ãã¡ãã»ãŒãžãã¥ãŒããã¹ãã§ã®èªèšŒãšæ¿èª
- å¥çŽã«ãããã¹ãïŒSpring Cloud ContractïŒ
- HtmlUnitã䜿çšããWeb UIãã¹ãã®ãµããŒã
- ã¢ããªã±ãŒã·ã§ã³æ§æã®æè»æ§-ãããã¡ã€ã«ããã¹ãæ§æãã³ã³ããŒãã³ããªã©
- ãã®ä»
ãŸããTDDãšãã¹ãå šè¬ã«ã€ããŠã®å°ãããªãããå¿ èŠãªçŽ¹ä»ã
ãã¹ãé§åéçº
TDDã¯éåžžã«åçŽãªã¢ã€ãã¢ã«åºã¥ããŠããŸã-ã³ãŒããèšè¿°ããåã«ãã¹ããèšè¿°ããŸãã çè«çã«ã¯æãããããã«èãããŸããããã°ãããããšå®è·µãšæè¡ã®ç解ãåŸããã ãã®åŸãã¹ããæžããšããéžæè¢ã¯æçœãªäžå¿«æãåŒãèµ·ãããŸãã éèŠãªãã©ã¯ãã£ã¹ã®1ã€ã¯ã ç¹°ãè¿ãã§ãã ãã¹ãŠãå°ãããçŠç¹ãçµã£ãå埩ãè¡ããŸããåå埩ã¯Red-Green-RefactorãšããŠèšè¿°ãããŸãã
èµ€ã®ãã§ãŒãºã§ã¯ãèœäžãã¹ããäœæããŸããæ確ã§ç解å¯èœãªçç±ãšèª¬æã§èœäžãããã¹ãèªäœãå®äºããŠã³ãŒãã®äœææã«åæ Œããããšãéåžžã«éèŠã§ãã ãã¹ãã§ã¯ã å®è£ ã§ã¯ãªãåäœããã§ãã¯ããå¿ èŠããããŸã ã ããã©ãã¯ããã¯ã¹ãã®ã¢ãããŒãã«åŸã£ãŠãã ããããã®åŸããã®çç±ã説æããŸãã
ã°ãªãŒã³ãã§ãŒãºã§ã¯ããã¹ãã«åæ Œããããã«æäœéå¿
èŠãªã³ãŒããèšè¿°ããŸã ã ç·Žç¿ããŠäžæ¡çãªãšããã«æã£ãŠããã®ã¯é¢çœãããšããããŸããïŒå€¢äžã«ãªããªãã»ããããã§ãïŒãã·ã¹ãã ã®ç¶æ
ã«å¿ããŠé¢æ°ãããŒã«å€ãè¿ãå Žåãæåã®ããã¹ãã¯åã«return true
ã
ãã¹ãŠã®ãã¹ããç·è²ã®å Žåã«ã®ã¿éå§ã§ãããªãã¡ã¯ã¿ãªã³ã°ãã§ãŒãºã§ã¯ãã³ãŒãããªãã¡ã¯ã¿ãªã³ã°ããŠé©åãªç¶æ ã«ããŸãã ç§ãã¡ãæžããã³ãŒãã«ã¯å¿ èŠãããããŸããããã®ãããå®å®ããã·ã¹ãã ã§ãªãã¡ã¯ã¿ãªã³ã°ãéå§ããããšãéèŠã§ãã ããã©ãã¯ããã¯ã¹ãã¢ãããŒãã¯ããªãã¡ã¯ã¿ãªã³ã°ãå®è£ ã®å€æŽã«åœ¹ç«ã€ã ãã§ãåäœã«ã¯åœ±é¿ããŸããã
å°æ¥ãTDDã®ããŸããŸãªåŽé¢ã«ã€ããŠã話ããŸããçµå±ã®ãšãããããã¯äžé£ã®èšäºã®ã¢ã€ãã¢ã§ãããããããã§ã¯ç¹ã«è©³çŽ°ã«èšåããŸããã ããããæšæºã®TDDæ¹å€ã«å¯Ÿå¿ããåã«ãããè³ã«ããç¥è©±ãããã€ãåãäžããŸãã
- ãTDDã¯ã³ãŒãã®çŽ100ïŒ ã®ã«ãã¬ããžã§ãããä¿èšŒã¯ããŸããã -ãã¹ãã«ããéçºã¯100ïŒ ã®ã«ãã¬ããžãšã¯é¢ä¿ãããŸããã ç§ãåããŠããå€ãã®ããŒã ã§ã¯ããã®ã¡ããªãã¯ã¯æž¬å®ãããããŠãããããããã£ã¡ããªãã¯ãšããŠåé¡ãããŠããŸããã ãããŠãã¯ãã100ïŒ ã®ãã¹ãã«ãã¬ããžã¯äœãæå³ããŸããã
- ãTDDã¯åçŽãªæ©èœã§ã®ã¿æ©èœããŸããããŒã¿ããŒã¹ã䜿çšããŠå®éã®ã¢ããªã±ãŒã·ã§ã³ãäœæããé£ããç¶æ ãäœæããããšã¯ã§ããŸãããã¯éåžžã«äººæ°ã®ããèšãèš³ã§ãããéåžžã¯ããã¹ãããŸã£ããæžããªãã»ã©è€éãªã¢ããªã±ãŒã·ã§ã³ããããããäžå¯èœã§ãããšè£è¶³ãããŸãã WebïŒSPAã®æç¡ã«ãããããïŒãã¢ãã€ã«ãAPIããã€ã¯ããµãŒãã¹ãã¢ããªã¹ãè€éãªéè¡ã·ã¹ãã ãã¯ã©ãŠããã©ãããã©ãŒã ããã¬ãŒã ã¯ãŒã¯ãããŸããŸãªèšèªãšãã¯ãããžãŒã§æžãããå°å£²ãã©ãããã©ãŒã ãªã©ããŸã£ããç°ãªãã¢ããªã±ãŒã·ã§ã³ã§TDDã¢ãããŒããæ©èœããŠããã®ãèŠãŸããã ãã®ããããç§ãã¡ã¯ãŠããŒã¯ã§ããã¹ãŠãç°ãªãããšããäžè¬çãªç¥è©±ã¯ãã»ãšãã©ã®å Žåããã¹ãã«æè³ããªãçç±ã§ãããæ¬åœã®çç±ã§ã¯ãããŸããïŒæ¬åœã®çç±ããããŸãïŒã
- ãTDDã«ã¯ãŸã ãã°ããããŸãã -ãã¡ãããä»ã®ãœãããŠã§ã¢ãšåæ§ã§ãã TDDã¯ãã°ããã°ããªããšããããšã§ã¯ãªããéçºããŒã«ã§ãã ãããã°ã奜ãã§ãã IDEã®ããã«ã ããã¥ã¡ã³ãã®ããã«ã ãããã®ããŒã«ã¯ãããããã°ããªãããšãä¿èšŒãããã®ã§ã¯ãªããã·ã¹ãã ã®è€éåã«å¯Ÿå¿ããã®ã«åœ¹ç«ã¡ãŸãã
TDDããã³äžè¬çãªãã¹ãã®äž»ãªç®æšã¯ãã·ã¹ãã ãå®å®ããŠåäœããŠãããšããèªä¿¡ãããŒã ã«äžããããšã§ãã ãããã£ãŠãã©ã®ãã¹ãæ¹æ³ã§ãããã¹ãã®æ°ãšæžã蟌ã¿ã決å®ããŸããã ã©ãã ãå¿ èŠã ãšæãããä»ããã«ã³ãŒããæ¬çªç°å¢ã«å ¥ããŠæ©èœããããšã確èªããããã«ã©ãã ãå¿ èŠããæžããŸããã ã ã¯ã€ãã¯ã€ã³ãã°ã¬ãŒã·ã§ã³ãã¹ããå¿ èŠãã€ååãªæåŸéåãã©ãã¯ããã¯ã¹ãšèŠãªãããªãã·ã§ã³ã®ãŠããããã¹ããæ€èšãã人ã ãããŸãã e2eã¯ã以åã®ããŒãžã§ã³ãžã®è¿ éãªããŒã«ããã¯ã®å¯èœæ§ãšã«ããªã¢ãªãªãŒã¹ã®ååšããã¹ãããããšã¯ããã»ã©éèŠã§ã¯ãªããšèšããŸãã ããŒã æ°-ã¢ãããŒããå€ããããèªåã®ããŒã ãèŠã€ããããšãéèŠã§ãã
ç§ã®ç®æšã®1ã€ã¯ãTDDã¹ããŒãªãŒã®ã2ã€ã®æ°å€ãè¿œå ããé¢æ°ã®ãã¹ããéããŠéçºããããšãã圢åŒããé¢ããå®éã®ã¢ããªã±ãŒã·ã§ã³ãã€ãŸãå®éã®ãããžã§ã¯ãã§åéãããæå°éã®ã¢ããªã±ãŒã·ã§ã³ã«ãŸã§èžçºããäžçš®ã®ãã¹ãæ¹æ³ãæ€èšããããšã§ãã ãã®ãããªåçŸå®çãªäŸãšããŠãç§èªèº«ãæœè±¡åã®ããã«çºæããå°ããªWebã¢ããªã±ãŒã·ã§ã³ã䜿çšããŸã å·¥å Ž ããŒã«ãªãŒããŒã«ãªãŒã±ãŒãå·¥å Ž ã æ¯ååå¥ã®ã¢ããªã±ãŒã·ã§ã³æ©èœã«çŠç¹ãåœãŠãå°ããªèšäºãæžããŠãTDDãéããŠAPIãã¢ããªã±ãŒã·ã§ã³ã®å
éšæ§é ãèšèšããäžå®ã®ãªãã¡ã¯ã¿ãªã³ã°ãç¶æã§ããããšã瀺ãã€ããã§ãã
çŸæç¹ã§èŠãŠããããã«ãäžé£ã®èšäºã®ãµã³ãã«èšç»ã¯æ¬¡ã®ãšããã§ãã
- ãŠã©ãŒãã³ã°ã¹ã±ã«ãã³-Red-Green-Refactorãµã€ã¯ã«ãå®è¡ã§ããã¢ããªã±ãŒã·ã§ã³ãã¬ãŒã ã¯ãŒã¯
- UIãã¹ããšåäœé§åèšèš
- ããŒã¿ã¢ã¯ã»ã¹ãã¹ãïŒã¹ããªã³ã°ããŒã¿ïŒ
- æ¿èªããã³èªèšŒãã¹ãïŒSpring SecurityïŒ
- ãžã§ããã¹ã¿ãã¯ïŒWebFlux + Project ReactorïŒ
- ïŒãã€ã¯ãïŒãµãŒãã¹ãšå¥çŽã®çžäºéçšæ§ïŒSpring CloudïŒ
- ã¡ãã»ãŒãžãã¥ãŒã®ãã¹ãïŒSpring CloudïŒ
ãã®å ¥éèšäºã§ã¯ããã€ã³ã1ãš2ã«ã€ããŠèª¬æããŸããã¢ããªã±ãŒã·ã§ã³ãã¬ãŒã ã¯ãŒã¯ãšãBDDã䜿çšããåºæ¬çãªUIãã¹ãããŸãã¯åäœé§ååéçºã¢ãããŒããäœæããŸãã åèšäºã¯ãŠãŒã¶ãŒã¹ããŒãªãŒããå§ãŸããŸãããæéãç¯çŽããããã®ãé£åãã®éšåã«ã€ããŠã¯èª¬æããŸããã ãŠãŒã¶ãŒã¹ããŒãªãŒã¯è±èªã§æžãããŸããããã®çç±ã¯ããã«æããã«ãªããŸãã ãã¹ãŠã®ã³ãŒãäŸã¯GitHubã«ãããŸãã®ã§ããã¹ãŠã®ã³ãŒãã解æããã®ã§ã¯ãªããéèŠãªéšåã®ã¿ã解æããŸãã
ãŠãŒã¶ãŒã¹ããŒãªãŒã¯ãéåžžã·ã¹ãã ã®ãŠãŒã¶ãŒã«ä»£ãã£ãŠæžãããèªç¶èšèªã¢ããªã±ãŒã·ã§ã³ã®æ©èœã®èª¬æã§ãã
ãŠãŒã¶ãŒã¹ããŒãªãŒ1ïŒãŠãŒã¶ãŒã«ããããããŒãžã衚瀺ããã
ã¢ãªã¹ãšããŠãæ°ãããŠãŒã¶ãŒ
Cake Factoryã®Webãµã€ãã«ã¢ã¯ã»ã¹ãããšãã«ãŠã§ã«ã«ã ããŒãžãèŠãã
ã±ãŒããã¡ã¯ããªãŒããã€çºå£²ãããã®ãããããããã«
åæ ŒåºæºïŒ
ã·ããªãªïŒèµ·åæ¥åã«Webãµã€ãã«ã¢ã¯ã»ã¹ãããŠãŒã¶ãŒ
ç§ãæ°ãããŠãŒã¶ãŒã ãšä»®å®ããŠ
Cake Factoryã®Webãµã€ãã«ã¢ã¯ã»ã¹ãããš
次ã«ããé¢å¿ããå¯ãããã ãããããšãããããŸãããšããã¡ãã»ãŒãžã衚瀺ãããŸã
ãããŠãããŠã§ããµã€ãã¯ãããã...ããšããã¡ãã»ãŒãžã衚瀺ãããŸã
ç¥èãå¿ èŠã«ãªããŸãïŒ Behavior-Driven DevelopmentãšCucumberã¯ã Spring Boot Testingã®åºæ¬ã§ãã
æåã®ãŠãŒã¶ãŒã¹ããŒãªãŒã¯éåžžã«åºæ¬çãªãã®ã§ãããç®æšã¯ãŸã è€éãã§ã¯ãªãã ãŠã©ãŒãã³ã°ã¹ã±ã«ãã³ïŒ TDDãµã€ã¯ã«ãéå§ããããã®æå°éã®ã¢ããªã±ãŒã·ã§ã³ïŒãäœæããããšã§ãã
Webããã³Moustacheã¢ãžã¥ãŒã«ã䜿çšããŠSpring Initializrã§æ°ãããããžã§ã¯ããäœæããåŸãæåã«build.gradle
ããã«å€æŽããå¿
èŠããããŸãã
- HtmlUnit
testImplementation('net.sourceforge.htmlunit:htmlunit')
è¿œå ããŸãã ããŒãžã§ã³ãæå®ããå¿ èŠã¯ãããŸãããGradleã®Spring BootäŸåé¢ä¿ç®¡çãã©ã°ã€ã³ã¯ãå¿ èŠã§äºææ§ã®ããããŒãžã§ã³ãèªåçã«éžæããŸã - ãããžã§ã¯ããJUnit 4ããJUnit 5ã«ç§»è¡ããŸãïŒ2018ã¯ã€ãŒãã«ããããïŒ
- Cucumberã«äŸåé¢ä¿ãè¿œå -BDDä»æ§ãäœæããããã«äœ¿çšããã©ã€ãã©ãª
- é¿ããããªã
contextLoads
ããã©ã«ãã§äœæãããCakeFactoryApplicationTests
ãåé€ããŸã
æŠããŠãããã¯ã¢ããªã±ãŒã·ã§ã³ã®åºæ¬çãªãã¹ã±ã«ãã³ãã§ãããã§ã«æåã®ãã¹ããäœæã§ããŸãã
ã³ãŒãå ãããã²ãŒãããããããããã«ã䜿çšãããŠãããã¯ãããžãŒã«ã€ããŠç°¡åã«èª¬æããŸãã
ãã ãã
Cucumberã¯ããå®è¡å¯èœãªä»æ§ãã®äœæã«åœ¹ç«ã€è¡åé§ååéçºãã¬ãŒã ã¯ãŒã¯ã§ãã èªç¶èšèªã§æžããããã¹ãïŒä»æ§ïŒãå®è¡ããŸãã Cucumberãã©ã°ã€ã³ã¯ãJavaïŒããã³ä»ã®å€ãã®èšèªïŒã®ãœãŒã¹ã³ãŒãã解æãã ã¹ãããå®çŸ©ã䜿çšããŠå®éã®ã³ãŒããå®è¡ããŸãã ã¹ãããå®çŸ©ã¯ã @When
ã @Then
@When
ã @Then
ãªã©ã®æ³šéãä»ããããã¯ã©ã¹ã¡ãœããã§ãã
Htmlunit
ãããžã§ã¯ãã®ããŒã ããŒãžã§ã¯ãHtmlUnitããJavaã¢ããªã±ãŒã·ã§ã³çšã®GUIã¬ã¹ãã©ãŠã¶ãŒããšåŒã³ãŸãã Seleniumãšã¯ç°ãªããHtmlUnitã¯å®éã®ãã©ãŠã¶ãèµ·åãããæãéèŠãªããšã«ã¯ãããŒãžããŸã£ããã¬ã³ããªã³ã°ãããDOMãšçŽæ¥é£æºããŸãã JavaScriptã¯Mozilla Rhinoãšã³ãžã³ãä»ããŠãµããŒããããŠããŸãã HtmlUnitã¯åŸæ¥ã®ã¢ããªã±ãŒã·ã§ã³ã«é©ããŠããŸãããã·ã³ã°ã«ããŒãžã¢ããªã«ã¯ããŸãé©ããŠããŸããã ã¯ããã«ãããã§ååã§ãã次ã«ããã¹ããã¬ãŒã ã¯ãŒã¯ãªã©ã®ã¢ããªã±ãŒã·ã§ã³ã§ããã¢ããªã±ãŒã·ã§ã³ã®åºç€ã§ã¯ãªãå®è£ ã®äžéšã«ã§ããããšã瀺ããŸãã
æåã®ãã¹ã
ããã§ãè±èªã§æžããããŠãŒã¶ãŒã¹ããŒãªãŒã圹ã«ç«ã¡ãŸãã 次ã®TDDå埩ãéå§ããããã®æé©ãªããªã¬ãŒã¯ãæå°éã®ãžã§ã¹ãã£ãŒã§å®è¡å¯èœãªä»æ§ã«å€æã§ããããã«èšè¿°ãããåãå ¥ãåºæºã§ãã
çæ³çã«ã¯ããŠãŒã¶ãŒã¹ããŒãªãŒã¯ãBDDä»æ§ã«åçŽã«ã³ããŒããŠå®è¡ã§ããããã«äœæããå¿ èŠããããŸãã ããã¯åžžã«ç°¡åãªããšã§ã¯ãªããåžžã«å¯èœãšããããã§ã¯ãããŸããããåžžã«éæã§ãããšã¯éããŸããããããã¯è£œåææè ãšããŒã å šäœã®ç®æšã§ãªããã°ãªããŸããã
ã ãããç§ã®æåã®æ©èœã
Feature: Welcome page Scenario: a user visiting the web-site visit before the launch date Given a new user, Alice When she visits Cake Factory web-site Then she sees a message 'Thank you for your interest' And she sees a message 'The web-site is coming in December!'
ã¹ãããã®èª¬æãçæãïŒ Intellij IDEAãã©ã°ã€ã³ãGherkinã®ãµããŒãã«åœ¹ç«ã¡ãŸãïŒããã¹ããå®è¡ãããšãåœç¶ãç·è²ã«ãªããŸã-ãŸã äœããã¹ãããŠããŸããã ãããŠãããã§ãã¹ãã«åãçµãéèŠãªæ®µéãæ¥ãŸã - ã¡ã€ã³ã³ãŒããæžããããã®ããã«ããã¹ããæžãå¿ èŠããããŸã ã
å€ãã®å ŽåãTDDãè¿œæŸãå§ãã人ã«ãšã£ãŠã¯ãstè¿·è ãããã«å ¥ããŸã-ãŸã ååšããªããã®ã®ã¢ã«ãŽãªãºã ãšããžãã¯ãé ã«å ¥ããããšã¯å°é£ã§ãã ãããã£ãŠããŠãŒã¶ãŒã¹ããŒãªãŒããå§ããŠçµ±åããã³ãŠãããã¬ãã«ã«è³ããŸã§ãã§ããã ãå°ããçŠç¹ãçµã£ãå埩ãè¡ãããšãéåžžã«éèŠã§ãã äžåºŠã«1ã€ã®ãã¹ãã«éäžããæ¿¡ããŠãŸã éèŠã§ã¯ãªãäŸåé¢ä¿ãç¡èŠããããšããããšãéèŠã§ãã äŸåé¢ä¿ã®ã€ã³ã¿ãŒãã§ã€ã¹ãŸãã¯ã¯ã©ã¹ãäœæããããã«ç©ºã®ãã¹ãã¯ã©ã¹ãçæãããã1ã€ã®äŸåé¢ä¿ãè¿œå ããå¥ã®äŸåé¢ä¿ãäœæãããªã©ã人ã ãç°¡åã«éããããããšã«æ°ä»ããŸããã
ã¹ããŒãªãŒããã»ãŒãã²ãŒã ã§ã¹ããŒã¿ã¹ãæŽæ°ããå¿ èŠããããå Žåãèªååããã³åœ¢åŒåããããšã¯éåžžã«å°é£ã§ãã ç§ã®äŸã§ã¯ãåã¹ãããã¯ãã³ãŒãã§èšè¿°ã§ããäžé£ã®ã¹ãããã§æ確ã«ã¬ã€ã¢ãŠãã§ããŸãã ãããæãåçŽãªäŸã§ãããããã»ã©å€ãã¯ç€ºãããŠããªãããšã¯æããã§ãããè€éããå¢ãã«ã€ããŠããèå³æ·±ããã®ã«ãªãããšãé¡ã£ãŠããŸãã
èµ€
ããã§ãæåã®æ©èœã®ããã«ã次ã®ã¹ãããã®èª¬æãäœæããŸããã
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class WelcomePage { private WebClient webClient; private HtmlPage page; @LocalServerPort private int port; private String baseUrl; @Before public void setUp() { webClient = new WebClient(); baseUrl = "http://localhost:" + port; } @Given("a new user, Alice") public void aNewUser() { // nothing here, every user is new by default } @When("she visits Cake Factory web-site") public void sheVisitsCakeFactoryWebSite() throws IOException { page = webClient.getPage(baseUrl); } @Then("she sees a message {string}") public void sheSeesAMessageThanksForYourInterest(String expectedMessage) { assertThat(page.getBody().asText()).contains(expectedMessage); } }
次ã®ç¹ã«æ³šæããŠãã ããïŒ
- æ©èœã¯å¥ã®ãã¡ã€ã«ãJUnit 4ã®
RunWith
ã¢ãããŒã·ã§ã³ã䜿çšããFeatures.java
ã«ãã£ãŠèµ·åããFeatures.java
RunWith
ã¯ããŒãžã§ã³5ããµããŒãããŠããŸããã -
@SpringBootTest
ã¢ãããŒã·ã§ã³ãã¹ãããã®èª¬æã«è¿œå ãããcucumber-spring
ãããããããã¯ã¢ããããŠãã¹ãã³ã³ããã¹ããæ§æããŸãïŒã€ãŸããã¢ããªã±ãŒã·ã§ã³ãèµ·åããŸãïŒ - ãã¹ãçšã®Springã¢ããªã±ãŒã·ã§ã³ã¯
webEnvironment = RANDOM_PORT
ããã®ã©ã³ãã ãªããŒãã¯@LocalServerPort
ã䜿çšããŠãã¹ãã«æž¡ãããSpringã¯ãã®æ³šéãèŠã€ããŠãã£ãŒã«ãå€ããµãŒããŒããŒãã«èšå®ããŸã
ãããŠãäºæ³ã©ããããã¹ã404 for http://localhost:51517
ãšã©ãŒ404 for http://localhost:51517
ã§ã¯ã©ãã·ã¥ããŸãã
ãã¹ããã¯ã©ãã·ã¥ãããšã©ãŒã¯ãç¹ã«åäœãã¹ããŸãã¯çµ±åãã¹ãã«é¢ããŠéåžžã«éèŠã§ããããããã®ãšã©ãŒã¯APIã®äžéšã§ãã ãã¹ããNullPointerException
ã¯ã©ãã·ã¥ããNullPointerException
ããã¯ããŸãè¯ããããŸããããBaseUrl configuration property is not set
-ãã£ãšè¯ãã§ãã
ç·è²
ãã¹ããã°ãªãŒã³ã«ããããã«ãæå°éã®HTMLã§ããŒã¹ã³ã³ãããŒã©ãŒãšãã¥ãŒãè¿œå ããŸããã
@Controller public class IndexController { @GetMapping public String index() { return "index"; } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Cake Factory</title> </head> <body> <h1>Thank you for your interest</h1> <h2>The web-site is coming in December!</h2> </body> </html>
ãã¹ãã¯ç·è²ã§ãã¢ããªã±ãŒã·ã§ã³ã¯åäœããŸãããå³ãããšã³ãžãã¢ãªã³ã°èšèšã®äŒçµ±ã§äœãããŠããŸãã
ãã¡ãããå®éã®ãããžã§ã¯ããšãã©ã³ã¹ã®åããããŒã ã§ã¯ããã¶ã€ããŒãšäžç·ã«åº§ã£ãŠã裞ã®HTMLããã£ãšçŸãããã®ã«å€ããŸãã ããããèšäºã®æ çµã¿ã®äžã§ãå¥è·¡ã¯èµ·ããããç女ã¯ã«ãšã«ã®ãŸãŸã§ãã
ãTDDã®ã©ã®éšåãèšèšã§ãããããšãã質åã¯ããã»ã©åçŽã§ã¯ãããŸããã ç§ã䟿å©ã ãšæã£ããã©ã¯ãã£ã¹ã®1ã€ã¯ãæåã¯UIããŸã£ããèŠãªãããšïŒããªãã®ç¥çµãç¯çŽããããã«ã¢ããªã±ãŒã·ã§ã³ãå®è¡ããããšããããŸããïŒããã¹ããæžããŠãããã°ãªãŒã³ã«ããŸã-ãããŠãå®å®ããåºç€ãæã¡ãããã³ããšã³ãã§äœæ¥ãããã¹ããåžžã«åèµ·åããŸãã
ãªãã¡ã¯ã¿ãªã³ã°
æåã®ã€ãã¬ãŒã·ã§ã³ã§ã¯ãç¹ã«ãªãã¡ã¯ã¿ãªã³ã°ã¯ãããŸããããæåŸã®10åéã¯ãªãã¡ã¯ã¿ãªã³ã°ãšããŠã«ãŠã³ãã§ããBulmaã®ãã³ãã¬ãŒããéžæããŸãããïŒ
çµè«ãšããŠ
ã¢ããªã±ãŒã·ã§ã³ã«ã¯ã»ãã¥ãªãã£äœæ¥ãããŒã¿ããŒã¹ãAPIããããŸãããããã¹ããšTDDã¯éåžžã«åçŽã«èŠããŸãã ãããŠãäžè¬çã«ããã¹ããã©ããããããäžçªäžã«ããUIãã¹ãã®ã¿ã«è§ŠããŸããã ããããããã«ãããŠãéšåçã«ãç¡é§ã®ãªãã¢ãããŒãã®ç§å¯ã¯ãäžåºŠã«1ã€ã®ã³ã³ããŒãã³ãã§ãå°ããªå埩ã§ãã¹ãŠãå®è¡ããããšã§ãã ããã«ããããã¹ãã«çŠç¹ãåœãŠããã¹ããåçŽåããã³ãŒãã®å質ãå¶åŸ¡ã§ããŸãã 次ã®èšäºã§ãã£ãšèå³æ·±ããã®ã«ãªãããšãé¡ã£ãŠããŸãã
åç §è³æ
- GitHubãããžã§ã¯ã
- ã³ã³ã³ãŒã¹ci
PSèšäºã®ã¿ã€ãã«ã¯æåã«èŠããã»ã©ã¯ã¬ã€ãžãŒã§ã¯ãããŸãããå€ãã®äººããã§ã«æšæž¬ããŠãããšæããŸãã ãããŒãã§ãã©ããããæ§ç¯ããæ¹æ³ãã¯ããã¹ããã©ãããïŒåŸã§è©³ãã説æããŸãïŒãšãã€ã®ãªã¹è±èªã§ã®ããŒããããã©ã³ã¯ããæå³ããã¹ããªã³ã°ããŒããžã®åç §ã§ãã