좋은 글을 발견하면 깜찍하게 인용,정리하고 폼나는 자기 의견까지 버무려서 글을 쓰는데 탁월한, 위자드닷컴 2008추천블로거 영회가 단골메뉴 단위테스트에 대한 글을 올렸다. 마침 애자일 스프링 책의 테스트관련 챕터를 쓰고 있어서 관심이 더 가서 글을 읽어봤다.

결론은 이렇다.

읽고 보니 그렇다. 테스트를 하지 않고 머리속으로 테스트 하기 좋은 코드를 작성하거나, 작성한 뒤에 테스트를 하면서 수정하기 보다는 당연히 먼저 테스트를 할 때 테스트 하기 좋은 코드를 작성하기가 수월할 것이다. :)

정답이다.

개발자가  작성하는 테스트코드의 함정은 이미 만들면서 설계해놓고, 이상적으로 동작할 것이라고 가정한 방식을 따라 교묘하게 안전하기만 한 테스트를 만들기 쉽다는 것이다. 전문 테스팅 훈련을 받거나, 자신의 코드에 대해서조차 까탈스러운 개발자가 아니라면 이미 머리로 설계해가면서 다 만든 코드에 대해서 꼼꼼한 테스트코드를 작성하기 힘들다. 게다가 테스트를 나중에 작성하는 건 정말 지루하다. 또 영회가 인용한 글에 나오는 것처럼 테스트하기가 어렵거나 단위테스트가 아닌 통합/기능테스트가 막 짬뽕되어 만들어지기가 쉽다. 테스트를 먼저 작성해야 테스터블한 코드기 때문이기도 하다.

 

그럼 이런 비슷한 얘기를 지금까지 여러번 블로그에 올리면서 단위테스트 또는 TDD 또는 테스트우선방식에 대해서 강조했던 영회는 과연 그렇게 하고 있을까? 했다면 "읽고보니 그렇더라"보다는  "해보니 그렇더라"라는 글을 올리지 않았을까라고 살짝 의심이 가지만, 그간의 영회의 테스트에 대한 뜨거운 열정과 폭발적인 관심을 생각해보면… 흠?

비단 테스트우선이나 TDD가 아니라 자동화된 테스트코드 작성에 대해서도 마찬가지이다.

 

사실 좋다고 알고 있고, 좋다고 이야기하고 떠들어댈 수 있는 것과 실제로 좋기 때문에 꼭 실천하고 하는 것에는 많은 차이가 있다. 나도 TDD가 거의 대부분의 경우에 최고의 개발전략이라고 생각하고 열심히 실천하려고 하고 있지만, 어느 순간 보면 습관적으로 테스트없이 정신없이 코드를 만들고 있는 내 모습을 보고 놀랄 때가 있다. TDD만큼 많은 사람의 입에 오르내리고 인정받는 것도 없지만, 내가 관찰한 결과는 정말 극도로 사용되지 않는 기술이기도 하다.

물론 "나중에라도 JUnit테스트를 만들면 TDD 아니에요?" 하는 사람은 일단 제외하고.

TDD에 대해서 교육까지 시키고, 글도 쓰고, 인정하는 사람들 조차도 왜 실천하지 않을까? 제일 종종 듣는 답변은 "일정상 테스트 작성할 시간이 없어서.."인데, 그 역시나 "TDD가 결국엔 개발시간을 단축시켜준다"라고도 본인 입으로 얘기했던 사람들의 말이라 변명으로 들리지도 않는다.

 

좋은 걸 알면서도 실천 안하는 이유는 뭘까?

여러가지 이유가 있겠지만 나는 가장 큰 이유는 "사실은 정말 좋은 줄 알지 못해서"라고 생각한다. 사람이 말하는 것과 행동하는 것이 다른 큰 이유는 그 말이 진심이 아니거나, 마음 속에선 부정하는 부분이 있기 때문이다. 말로는 인정하지만 몸으로는 부정하는 것 아닐까?

물론 오랜 습관의 문제도 있겠고, 환경 탓을 할 수도 있고, 팀의 문화나 뭐 살인적인 개발일정 등등을 다 얘기할 수도 있겠지만, 개인적인 여유 시간에 작은 코딩을 하나 할 때도 테스트를 안만드는 것을 보면 그런 것들은 다 치사한 변명이었을 것이라는 의심만 든다. 차라리 "TDD해보니 별거 아닌 것 같다"라던가 "TDD는 실력이 아주 뛰어난 사람이 아니면 힘들다"라는 식의 답변이 더 솔직해 보인다. 그런 말을 하는 사람들은 어느 때가 되면 자신의 생각이 잘못됐음을 인정할 가능성이라도 있겠지만, 말로는 항상 좋다고 하지만 막상 현실에선 실천하지 않는 사람은 평생가도 못할지도 모른다.

 

김현국님의 회사 모토가 "개발하다 죽자"라던데, 적어도 TDD를 하려면 "TDD하다 죽자" 정도의 굳은 결심이나, "정말 테스트를 먼저 작성해야 좋은 코드를 작성할 수 있다"라는 진정한 확신과 "좋은 코드를 작성하는 개발자가 되고 싶다"는 열망이 함께 있어야 하지 않을까.

 

참, TDD하다 죽으면 안되니 "TDD하고나서 죽자"로 바꿔야겠다.

Related posts:

  1. 테스트 주도 개발 TDD 실천법과 도구 – 채수원
  2. 모든 개발자는 사실 TDD를 하고 있다
  3. 유쾌한 이슈처리 재촉 메일
  4. TDD와 TLP
  5. 오픈소스 소프트웨어에서 오픈소스 코드가 가지는 의미는?
  6. TDD 안티 패턴

Facebook comments:

to “알면서 왜 안할까? TDD”

  1. although web sites we backlink to below are considerably not associated to ours, we really feel they may be in fact worth a go by way of, so have a look

  2. Thank you for another informative blog. Where else may just I get that type of info written in such a perfect method? I have a challenge that I’m simply now running on, and I’ve been at the glance out for such info.

  3. Oh my goodness! Incredible article dude! Many thanks, However I am going through difficulties with your RSS. I don’t understand why I am unable to join it. Is there anyone else getting similar RSS issues? Anybody who knows the solution can you kindly respond? Thanks!!

  4. Every once inside a while we pick blogs that we study. Listed beneath would be the newest websites that we opt for

  5. the time to read or visit the content material or internet sites we have linked to beneath the

  6. Sites of interest we have a link to

  7. I’ve been absent for a while, but now I remember why I used to love this website. Thank you, I will try and check back more frequently. How frequently you update your web site?

  8. whoah this weblog is fantastic i really like studying your articles. Keep up the good paintings! You realize, a lot of people are looking around for this information, you could help them greatly.

  9. I have been surfing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all web owners and bloggers made good content as you did, the internet will be much more useful than ever before.

  10. I’d like to thank you for the efforts you have put in penning this blog. I’m hoping to check out the same high-grade content by you later on as well. In fact, your creative writing abilities has motivated me to get my own, personal site now ;)

  11. It’s hard to finmd experienced people in this particular topic, but
    youu seem like you know what you’re talking about!
    Thanks

    my website https://mukck.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/

  12. just beneath, are a lot of absolutely not associated web sites to ours, however, they are surely really worth going over

  13. please check out the internet sites we adhere to, such as this one particular, because it represents our picks from the web

  14. check beneath, are some completely unrelated internet websites to ours, nevertheless, they’re most trustworthy sources that we use

  15. we like to honor several other online internet sites on the web, even though they arent linked to us, by linking to them. Underneath are some webpages really worth checking out

  16. one of our visitors just lately encouraged the following website

  17. Excellent blog you have here.. It’s difficult to find good quality writing like yours nowadays. I truly appreciate people like you! Take care!!

  18. check beneath, are some entirely unrelated websites to ours, however, they may be most trustworthy sources that we use

  19. check beneath, are some entirely unrelated websites to ours, on the other hand, they’re most trustworthy sources that we use

  20. we prefer to honor many other world-wide-web internet sites around the web, even if they arent linked to us, by linking to them. Under are some webpages really worth checking out

  21. Wonderful story, reckoned we could combine a few unrelated data, nevertheless genuinely really worth taking a look, whoa did one particular study about Mid East has got a lot more problerms also

  22. usually posts some incredibly fascinating stuff like this. If youre new to this site

  23. Yes! Finally someone writes about plenty of fish dating site.

  24. Greetings I am so thrilled I found your website, I really found you by mistake, while I was looking on Bing for something else, Anyways I am here now and would just like to say kudos for a marvelous post and a all round interesting blog (I also love the theme/design), I don’t have time to go through it all at the minute but I have book-marked it and also added in your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the excellent job.

  25. here are some hyperlinks to web pages that we link to due to the fact we consider they are really worth visiting

  26. You made some decent points there. I checked on the web to find out more about the issue and found most people will go along with your views on this web site.

  27. I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very internet smart so I’m not 100% positive. Any recommendations or advice would be greatly appreciated. Kudos

  28. You really make it seem so easy along with your presentation but I to find this topic to be really something that I believe I’d by no means understand. It kind of feels too complex and extremely vast for me. I am having a look ahead for your subsequent publish, I’ll attempt to get the dangle of it!

  29. here are some links to web pages that we link to for the reason that we believe they’re worth visiting

  30. here are some hyperlinks to websites that we link to because we feel they’re really worth visiting

  31. hello there and thank you for your information – I have certainly picked up anything new from right here. I did however expertise a few technical issues using this web site, since I experienced to reload the site lots of times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I’m complaining, but sluggish loading instances times will sometimes affect your placement in google and could damage your high-quality score if ads and marketing with Adwords. Anyway I’m adding this RSS to my e-mail and could look out for a lot more of your respective intriguing content. Ensure that you update this again very soon..

  32. You’ve made some really good points there. I looked on the internet to find out more about the issue and found most people will go along with your views on this web site.

  33. we prefer to honor several other internet sites around the internet, even when they arent linked to us, by linking to them. Under are some webpages worth checking out

  34. Good ¡V I should certainly pronounce, impressed with your web site. I had no trouble navigating through all tabs as well as related info ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your customer to communicate. Nice task..

  35. Hiya very cool blog!! Guy .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds also…I am glad to search out numerous helpful information here in the post, we need develop more techniques on this regard, thanks for sharing.

  36. Have you ever considered about including a little bit more than just your articles? I mean, what you say is fundamental and all. Nevertheless just imagine if you added some great graphics or video clips to give your posts more, “pop”! Your content is excellent but with pics and video clips, this blog could certainly be one of the greatest in its niche. Amazing blog!

  37. Here is a great Blog You might Come across Fascinating that we Encourage You

  38. The data talked about within the article are several of the most beneficial available

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2017 Toby's Epril Suffusion theme by Sayontan Sinha