TDDã«å ¥éãããä¸çªè¯ãã®ãåããï¼ç¶ã ï¼
WEB+DB PRESS vol.35 ã®åçµã®ç¶ããä»æ¥ã¯ç¬¬6ç« ã§ãã¢ãã¯ã¨DIã®è©±é¡ã§ããã
S2ãã¬ã¼ã ã¯ã¼ã¯ã®MockInterceptorãåã便å©ã ã¨ç¥ãã¾ãããæ¥ããããªãããã¢ãã¯ã使ã£ãã¦ããããã¹ãã¨èãã¦æ³åãã¦ããã®ã¯ãDIã§å·®ãæãã¢ãã¯ã§ã¯ãªãæ§æ¥ã®ã¢ãã ã£ãã®ã§ãç®ããã¦ãã³ã§ãããMockInterceptorã使ã£ããã¹ãã³ã¼ãããã£ã¨èªã¿ããã§ãã
ã¨ããã§ãJUnitã®ä½¿ãæ¹ã§ãããã¾ããã
ä»å使ç¨ãã¦ããJUnitã¯ããã¼ã¸ã§ã³3.8.2ãªã®ã§ããã¹ãã¡ã½ããã«å ¥ãåã®æºåå¦çã¯ãsetUpã¡ã½ããã«æ¸ãã¦ãã¾ããæ¬æã®pp.39-40ã§ã¯ããã¹ãã±ã¼ã¹ã1ã¤ã ãã®æ¬¡ã®ãããªç¶æ ããã
- ãã¹ãã±ã¼ã¹ï¼1ã¤ã ãï¼
- setUp()
- testDaoåã®ããªãã£ã¯ã¹ã¨IDããDaoå¼ã³åºããè¡ã()
setUpã¡ã½ããããªãã¼ã ãããã¹ãã±ã¼ã¹ãããã«1ã¤è¿½å ãã¦ãã¾ãã
- ãã¹ãã±ã¼ã¹ãã®1
- setUpDaoåã®ããªãã£ã¯ã¹ã¨IDããDaoå¼ã³åºããè¡ã() // ä¸ã®setUp()ããªãã¼ã
- testDaoåã®ããªãã£ã¯ã¹ã¨IDããDaoå¼ã³åºããè¡ã()
- ãã¹ãã±ã¼ã¹ãã®2
- setUpDaoåã®ããªãã£ã¯ã¹ã¨IDããDaoå¼ã³åºããè¡ãä¸è§æ¸¬é()
- testDaoåã®ããªãã£ã¯ã¹ã¨IDããDaoå¼ã³åºããè¡ãä¸è§æ¸¬é()
ãã®å¾ãã°ãªã¼ã³ãã¼ã«ãªããã¨ã確èªããããã§ãããæå ã§ã¯ã¬ããã«ãªãã¾ãããã©ãããsetUpã¡ã½ããã1ã¤ããã¤ã¡ã½ããåããsetUpãã®ã¨ãã ããsetUpã¡ã½ãããå®è¡ããã¦ãã¾ããï¼1ã¤ç®ã®ãã¹ããéããªããªã£ãã追å ãããã¹ãã±ã¼ã¹ãã®2ãå¯ä¸ã®ãã¹ãã«ãã¦ã¿ããéã£ãã®ã§ã追å ãããã¹ããããããããã§ã¯ãªãï¼
å®è¡ã®ä»æ¹ãééã£ã¦ããã®ãã1ã¤ã®ãã¹ãã¯ã©ã¹ã§è¤æ°ã®setUpã使ãã«ã¯ä½ãè¨å®ãå¿ è¦ãªã®ãã»ã»ã»ã¾ã åãã£ã¦ãã¾ãããæ ããªãããã