1 / 35

TDD

TDD. elaborate 2011-06-10. 들어가기 전에 …. This is not a whole story of TDD. This is not a whole story of developing Actually, there is no neat end of developing :P. 필요성. 보통 개발을 한다면 ,,, 우선 중요한 기능을 다 짜보고 간단하게 실행해보고 예외 케이스들에 대한 처리 생각해보고 버그가 있으면 고친다

aliza
Download Presentation

TDD

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TDD elaborate 2011-06-10

  2. 들어가기 전에… • This is not a whole story of TDD. • This is not a whole story of developing • Actually, there is no neat end of developing :P

  3. 필요성 • 보통 개발을 한다면,,, • 우선 중요한 기능을 다 짜보고 • 간단하게 실행해보고 • 예외 케이스들에 대한 처리 생각해보고 • 버그가 있으면 고친다 • printf, print, system.out.println, print_r…… • 오랜 시간 동안 스스로 자아성찰을 하게 된다 (나는 왜 코드를 이렇게 짰을까……) • 문제가 어디가 있는지 찾기 어렵다 • 고친 다음 혹시 부작용이 있지는 않을까 걱정을 한다 (A를 고치면 B가안되고 B를 고치면 C가 안되고 C를고치면 A가 안되고…) • 즉, 어디까지 보장된 실행을 하는지 가늠하기 쉽지 않다 • 알 수 없는 기능이 만들어 지거나, 코드가 산으로 바다로 우주로 우주 밖으로!

  4. 이런 거 싫다 • 자기를 탓하게 되고성취감이 떨어지더라 • 기능 구현 보다는 개발 시간에 집착한다 • 중간에 잘 하고 있는지 알기 어렵다 • 필요 이상의 구현을 하고 있다 • 결론 : 생각이 많아진다

  5. 그렇다면, • 개발 방법을 다르게 할 수는 없을까? • 결국 사용하는 것 사용자. 그렇다면 오히려 개발을 주도하는 것은 개발자의 생각이 아니고 사용자의 사용 방식이 아닐까 • 틀린 말은 아닌 것 같다. 그래 그럼 새로운 개발 방법을 익히자!

  6. What is TDD? • Test Driven Development • http://en.wikipedia.org/wiki/Test-driven_development • It is a Software Development Process • Family of Agile • Key words • Automated unit tests • Assertions • Refactoring • Writing a code

  7. Be careful! • TDD is not an omniscience technique! • Usually, imported as part of process • However, if you decided, please keep it during development

  8. TDD Process • A Process cycle is composed in 4-5 stages • Adding a test • Running a test and check • Writing code • Testing again • Refactoring the code

  9. Process Diagram Refactoring

  10. 좀 더 쉽게 • 고객(실질 사용자)와함께 TODO List를 만든다 • Backlog를 만든다는 말을 여기서 쓸 거다 • 나에게 적당한 일을 고른다 • TDD과정을 타면서 열심히 개발을 한다 • 다 되었으면 저장소에 반영하고 Review를 받는다 • 위 3 과정을 TODO List가 빌 때까지 반복한다 • 프로그램 개발이 끝났다

  11. Good to Frameworks! • JUnit (Java unit test framework) • Python unit test module • import unittest • Django unit test module • from django.utils import unittest • A lot of unit testing frameworks • http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks • xUnit is a general term for unit test frameworks What relation?

  12. 잠깐! • What is Agile? • What is Unit test? • What is Assertion? • What is Refactoring? • What is Framework?

  13. Agile • A group of software development • http://en.wikipedia.org/wiki/Agile_software_development • http://agilemanifesto.org/ • Break tasks into Short term work • Cross function, self organizing • 모두가 다같이 같은 위치에서 개발을 • Face to Face communication • Customer Representatives • Each routine should make working software • For a short term project – not a 10 year project, over 50 people project • Matched to the current trend of software development

  14. All right.. • Let’s see examples • Bowling Scoring Program (Java with Junit) • 학점을 계산합시다 (Python with Django test)

  15. Bowling Score • Do you like bowling? • Have you ever have a question about how bowling score is graded? • I didn’t know until this seminar…

  16. Bowling keyword Game Throw Frame Spare Strike Understandable???

  17. Start of thinking • What can happen in Bowling Game? • When a ball is thrown • add knock downed pins • Want to know score of a frame • Want to total score of a current game

  18. Thinking of Tests • Start of thinking Test Cases • Adding score • Getting Score Of a Frame • Getting Total score

  19. Write test codes publicvoidtestGameStart() { Game g = new Game(); assertEquals(0, g.getScoreOfFrame(0)); assertEquals(0, g.score()); } Understandable??? publicvoidtestThrowOnce() { setUp(); game.add(5); assertEquals(5, game.score()); } Any question??? publicvoidtestThrowTwice() { setUp(); game.add(5); game.add(6); assertEquals(11, game.score()); }

  20. More test codes publicvoidtestThrowWithSpare() { setUp(); game.add(3); game.add(7); game.add(6); game.add(2); assertEquals(16, game.getScoreOfFrame(1)); // 3 + 7 + (6) } Understandable??? publicvoidtestThrowWithStrike() { setUp(); game.add(10); game.add(7); game.add(1); assertEquals(18, game.getScoreOfFrame(1)); // 10 + (7+1) } Any question???

  21. Practice • Let’s see Eclipse • We will cover there • Quite lots of explanation would be given

  22. 학점을 계산합시다 • 괜찮아 보이는 스토리를 못 짜겠다 (미안) • 규칙 설명 : • Sigma (학점 * 점수) / Sigma(학점)

  23. Specification • Web based 학점 계산하기 • Users would have simple Interface • 과목수를 받고, (input) • 과목과 점수를 입력한 다음 (get) • 평점을 내준다 (result) • Django를 쓴다 • 모든 과목의 학점은 3학점이라 치자

  24. Like this! <form action="get.html" method="get"> <div> <input type="text" size="5"> <input type="submit" value="Get!"> </div> </form> <form action="result.html" method="post"> <div> <input type="text" name="s1"> <select name="g1"> <option value="1">A+</option> <option value="2">A0</option> <option value="3">A-</option> …… </select> …… </div>

  25. Start Django • You already know • django-admin startprojectgpa • django-admin startapp input • django-admin startapp get • django-admin startapp result • I know it is redundant work

  26. Thinking of Tests • Right inputs • Right formats and values of POST, GET • Right Result of GPA

  27. Practice • Let’s see vim • We will cover there • It seems to be easy, huh? • But, there would be quite a lot of explanation

  28. This not end!!!

  29. Category of Tests • Authentication Test • DB Test • HTTP Test • …… • Everything can be tested and should be tested

  30. Be Careful again • Don’t be afraid of Failing Tests! • Fail is mother of pass?!?! • Be thoughtful when you writing a Test • Don’t think whole at once • Don’t make testing lead you, you must lead the tests!

  31. Please Study hard! • 여러분 것이 지금까지 본건 TDD의 극히 일부분, framework이 제공해 주는 것의 반의반의반 (1/8)도 안 썼다 • 반드시 각각에 대한 문서를 읽어보자 • Reference는 끝 페이지

  32. It Looks Hard • No, it’s not that hard • I just make it verbose to show you • This seminar is not that practical • Always, first time is hard • More trials, more easy work

  33. Keep it mind • Homework • I will check if there are test cases in your mini-project next week • Be prepared!

  34. Q&A • Thanks • Special thanks to Combacsa

  35. Reference • http://www.agiledata.org/essays/tdd.html • http://www.martinfowler.com/bliki/Xunit.html • http://en.wikipedia.org/wiki/Test_automation • http://en.wikipedia.org/wiki/XUnit • http://en.wikipedia.org/wiki/Test-driven_development • https://docs.djangoproject.com/en/dev/topics/testing/ • http://www.junit.org/ • http://en.wikipedia.org/wiki/Agile_software_development • http://agilemanifesto.org/ • http://sparcs.org/seminar/attachment/combacsa-20100612-2.pptx

More Related