Tdd with JUnit 1

50 %
50 %
Information about Tdd with JUnit 1
Technology

Published on May 29, 2014

Author: ssusercef361

Source: slideshare.net

Description

TDD with JUnit 1
We are the Java Experts ์Šคํ„ฐ๋”” ์ž๋ฃŒ

TDDwith JUnit Test Driven Development Junyoung Lee

๋Œ€๊ฐœ

 ย ์šฐ๋ฆฌ๋Š” ๊ฐœ๋ฐœ์„

 ย ํ•˜๊ณ  ํ…Œ์ŠคํŠธ๋ฅผ

 ย ํ•ฉ๋‹ˆ๋‹ค.

์ž˜

 ย ๋Œ์•„๊ฐ€๋‚˜ ?

๊ฐœ๋ฐœ ๊ธฐ๊ฐ„์ด ๊ธธ์–ด์งˆ ์ˆ˜๋ก ๊ฐœ๋ฐœ์ž์˜ ๋ชฉํ‘œ์˜์‹์ด ํ๋ ค์ง„๋‹ค ์ž‘์—…์ด ๊ธธ์–ด์งˆ ์ˆ˜๋ก ํ™•์ธ์ด ์–ด๋ ต๋‹ค ๊ฐœ๋ฐœ์ž์˜ ์ง‘์ค‘๋ ฅ์ด ํ•„์š”ํ•ด์ง„๋‹ค ๋…ผ๋ฆฌ์ ์ธ ์˜ค๋ฅ˜๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ต๋‹ค ์ฝ”๋“œ์˜ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ๋ณ€๊ฒฝ ์ด๋ ฅ์„ ๊ฐœ๋ฐœ์ž์˜ ๊ธฐ์–ต์— ์˜์กดํ•˜๊ฒŒ ๋œ๋‹ค ๊ท€์ฐจ๋‹ˆ์ฆ˜์˜ ์ฆ๊ฐ€๋กœ ํ…Œ์ŠคํŠธ๋ฅผ ๊ฐ„์†Œํ™” ํ•˜๊ฒŒ ๋œ๋‹ค ์ฝ”๋“œ ์ˆ˜์ • ์‹œ ์ •์ƒ ๋™์ž‘์„ ๋ณด์žฅํ•˜๊ธฐ ์–ด๋ ต๋‹ค ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด๋ ค๋ฉด ๋ณ€๊ฒฝ ๋“ฑ์˜ ์„ ํ–‰ ์ž‘์—…์ด ํ•„์š” ํšŒ๊ท€ ํ…Œ์ŠคํŠธ๊ฐ€ ํฌ๊ท€ ํ…Œ์ŠคํŠธ๊ฐ€ ๋˜๊ธฐ ์‰ฝ๋‹ค ๊ฐœ๋ฐœ์ž์˜ ๋…ธ๋™๋ ฅ์„ ํ•„์š”๋กœ ํ•˜๊ฒŒ ๋œ๋‹ค - ํ…Œ์ŠคํŠธ ์ฃผ๋„ ๊ฐœ๋ฐœ TDD ์‹ค์ฒœ๋ฒ•๊ณผ ๋„๊ตฌ ์ค‘

TDD์—์„œ๋Š” ํ…Œ์ŠคํŠธ๋ฅผ

 ย ์ž‘์„ฑํ•˜๊ณ , ๊ฐœ๋ฐœ์„

 ย ํ•ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ๋„

 ย ์—†๋Š”๋ฐ

 ย ๋ฌด์Šจ

 ย ํ…Œ์ŠคํŠธ๋ฅผ

 ย ๋จผ์ €?

TDD

Need ๋ฌด์—‡์„ ํ…Œ์ŠคํŠธ ํ•  ๊ฒƒ์ธ๊ฐ€? Test ์‹คํŒจํ•˜๋Š” ํ…Œ์ŠคํŠธ ์ž‘์„ฑ Code ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜๋Š” ์ฝ”๋“œ ์ž‘์„ฑ Refactoring ์ฝ”๋“œ์˜ ์ค‘๋ณต ์ œ๊ฑฐ TDD Flow

Simple Code Ron jeffries said โ€œClean code that worksโ€

์˜ˆ์ธก ๊ฐ€๋Šฅํ•œ ๊ฐœ๋ฐœ ๋ฐฉ๋ฒ•์ด๋‹ค ๋Š์ž„์—†์ด ๋ฐœ์ƒํ•  ๋ฒ„๊ทธ์— ๋Œ€ํ•ด ๊ฑฑ์ •ํ•˜์ง€ ์•Š๊ณ  ์ผ์ด ์–ธ์ œ ๋งˆ๋ฌด๋ฆฌ ๋  ์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค ์ฝ”๋“œ๊ฐ€ ๊ฐ€๋ฅด์ณ์ฃผ๋Š” ๋ชจ๋“  ๊ตํ›ˆ์„ ํ•™์Šตํ•  ๊ธฐํšŒ๋ฅผ ๊ฐ–๊ฒŒ ๋œ๋‹ค ๋‹น์‹ ์ด ๋งŒ๋“  ์†Œํ”„ํŠธ์›จ์–ด๋Š” ์‚ฌ์šฉ์ž์˜ ์‚ถ์„ ํ–ฅ์ƒ์‹œ์ผœ ์ค€๋‹ค ๋™๋ฃŒ๋“ค์ด ๋‹น์‹ ์„ ์กด๊ฒฝํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค ๋‹น์‹  ๋˜ํ•œ ๋™๋ฃŒ๋“ค์„ ์กด๊ฒฝํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค ์ž‘์„ฑํ•˜๋Š” ๋™์•ˆ ๊ธฐ๋ถ„์ด ์ข‹๋‹ค - ํ…Œ์ŠคํŠธ ์ฃผ๋„ ๊ฐœ๋ฐœ ์ค‘

Getting

 ย started

 ย TDD with

 ย JUnit

Eclipse๋ฅผ ์‚ฌ์šฉํ•  ๊ฒ๋‹ˆ๋‹ค. JUnit ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ์˜ ๋นŒ๋“œ ํŒจ์Šค์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์‹œ์ž‘ํ•ด ๋ด…์‹œ๋‹ค. ํ™˜๊ฒฝ ์„ค์ • ์ด ์ •๋„๋Š” ์Šค์ƒท ์—†์–ด๋„ ๋˜๊ฒ ์ช™?

๋‘ ๋‚ ์งœ์˜ ์ผ ์ˆ˜ ์ฐจ์ด๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด ๋ด…์‹œ๋‹ค. 20140314 - 20140310 = 4 ์˜ˆ์ œ ์ถœ์ฒ˜ - https://wikidocs.net/224

ํ…Œ์ŠคํŠธ

 ย ์ผ€์ด์Šค

 ย ์ž‘์„ฑ 1. ๋‘ ๋‚ ์งœ์˜ ์ฐจ์ด ์ผ ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค. 2. ํŠน์ • ์ผ์ž์˜ ์ด ์ผ ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค. 3. ์ „๋…„๋„๊นŒ์ง€์˜ ์ด ์ผ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค. < 4. ์ „๋‹ฌ๊นŒ์ง€์˜ ์ด ์ผ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค. 5. ํ•ด๋‹น ์ผ์ž๊นŒ์ง€์˜ ์ด ์ผ ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค.

ํ…Œ์ŠคํŠธ

 ย ์ฝ”๋“œ

 ย ์ž‘์„ฑ public class SubDateTest extends TestCase{ public static void main(String[] args) { junit.textui.TestRunner.run(SubDateTest.class); } public void testGetYearDay() { assertEquals(0, SubDate.getYearDay(1)); assertEquals(365, SubDate.getYearDay(2)); } }

์•„์ง SubDate๋Š” ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์™œ๋ƒ๊ตฌ์š”? ์ด์ œ

 ย ๋งŒ๋“ค๊ฑฐ๋‹ˆ๊นŒ์š”. ์Šฌ์Šฌ

 ย ์ ์‘ํ•˜์„ธ์š”.

์ผ๋‹จ!

 ย ์ปดํŒŒ์ผ์„

 ย ์„ฑ๊ณตํ•˜๊ฒŒ

 ย ํ•˜๊ธฐ

 ย ์œ„ํ•ด์„œ public class SubDate { public static int getYearDay(int year) { return 1; } }

ํ…Œ์ŠคํŠธ

 ย ๊ฒฐ๊ณผ๋Š”? ์„ฑ๊ณตํ• 

 ย ์ˆ˜

 ย ์žˆ์„๋ฆฌ๊ฐ€

 ย ์—†์ฃ .

ํ…Œ์ŠคํŠธ๋ฅผ

 ย ์„ฑ๊ณต์‹œ์ผœ

 ย ๋ด…์‹œ๋‹ค. public static int getYearDay(int year) { if (year == 1) return 0; return 365; }

์งœ์ž์ž”~

๊ฐ€์žฅ ๋นจ๋ฆฌ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ค์–ด๋ผ. ์–ด๋–ค ์ฃ„์•…์„ ์ €์งˆ๋Ÿฌ๋„ ์ƒ๊ด€์—†๋‹ค. - Kent Beck

์•„์ง

 ย getYearDay๋Š” ์™„์ „ํ•˜์ง€

 ย ์•Š์Šต๋‹ˆ๋‹ค. ์•„๋ž˜

 ย ํ…Œ์ŠคํŠธ๋Š”

 ย ์‹คํŒจํ•˜๊ฒ ์ฃ  assertEquals(365+365+365+366, SubDate.getYearDay(5));

public void testLeapYear() { assertTrue(SubDate.isLeapYear(0)); assertFalse(SubDate.isLeapYear(1)); assertTrue(SubDate.isLeapYear(4)); } ์œค๋…„๋„

 ย ๊ณ ๋ คํ•ด์•ผ๊ฒ ์ฃ ? ์œค๋…„์„

 ย ์œ„ํ•œ

 ย ํ…Œ์ŠคํŠธ

 ย ์ฝ”๋“œ

 ย ์ž‘์„ฑ

์œค๋…„

 ย ๊ณ„์‚ฐ

 ย ์ฝ”๋“œ

 ย ์ž‘์„ฑ ublic static boolean isLeapYear(int year) { if (year == 0) return true; if (year == 1) return false; if (year == 4) return true; return false; }

public static boolean isLeapYear(int year) { if (year % 4 == 0) return true; return false; } ๋ฆฌํŒฉํ† ๋ง

์œค๋…„

 ย ์ฒดํฌ

 ย ๋ฉ”์„œ๋“œ๋„

 ย ์™„์ „ํ•˜์ง„

 ย ์•Š์Šต๋‹ˆ๋‹ค. 1. 4๋กœ ๋‚˜๋ˆ„์–ด์„œ ๋–จ์–ด์ง€๋Š” ํ•ด๋Š” ์œค๋…„์ด๋‹ค. 2. 100์œผ๋กœ ๋‚˜๋ˆ„์–ด์„œ ๋–จ์–ด์ง€๋Š” ํ•ด๋Š” ์œค๋…„์ด ์•„๋‹ˆ๋‹ค. 3. 400์œผ๋กœ ๋‚˜๋ˆ„์–ด์„œ ๋–จ์–ด์ง€๋Š” ํ•ด๋Š” ์œค๋…„์ด๋‹ค.

public void testLeapYear() { assertTrue(SubDate.isLeapYear(0)); assertFalse(SubDate.isLeapYear(1)); assertTrue(SubDate.isLeapYear(4)); assertTrue(SubDate.isLeapYear(1200)); assertFalse(SubDate.isLeapYear(700)); } ํ…Œ์ŠคํŠธ

 ย ์ฝ”๋“œ

 ย ์ˆ˜์ •

getLeapYear

 ย ์ˆ˜์ • public static boolean isLeapYear(int year) { if (year % 400 == 0) return true; if (year % 100 == 0) return false; if (year % 4 == 0) return true; return false; }

assertEquals(365+365+365+366, SubDate.getYearDay(5)); ์œค๋…„์„

 ย ๊ณ ๋ คํ•œ

 ย ํ…Œ์ŠคํŠธ

 ย ์ฝ”๋“œ

public static int getYearDay(int year) { int result = 0; for (int i = 1; i < year; i++) { if (isLeapYear(i)) result += 366; else result += 365; } return result; } ์œค๋…„์„

 ย ๊ณ ๋ คํ•œ

 ย getYearDay

์ง€๊ธˆ๊นŒ์ง€ ํ•œ ๊ฒƒ๋“ค์„ ์ •๋ฆฌํ•ด ๋ด…์‹œ๋‹ค.

Add a comment

Related presentations

Presentaciรณn que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generarรก el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

JUnit - About

JUnit is a simple framework to write repeatable tests. ... Work on JUnit 5 - Milestone 1 has started. Explore and give feedback!
Read more

Introduction to Java TDD - part 1 - fruzenshtein.com

Introduction to TDD with JUnit. Main test driven development principles. Theory and examples provided not only for Java but also for any programming language.
Read more

java - logging in TDD with Junit - Stack Overflow

logging in TDD with Junit. up vote 1 down vote favorite. Recently some one told me that we should not have logging in JUnit test cases or TDD in general.
Read more

Testgetriebene Entwicklung โ€“ Wikipedia

TDD nach Kent Beck Unit-Tests und mit ... TDD and Acceptance TDD for Java developers. ISBN 1-932394-85-0. ... Testgetriebene Entwicklung mit JUnit und FIT ...
Read more

TDD with JUnit Test Framework - YouTube

TDD with JUnit Test Framework ... Replace Conditionals with Polymorphism TDD + Java + JUnit - Duration: ... 1:28:44. 9876501234 Views 13,862 views.
Read more

JUnit 4 Tutorial, Java-Tests mit JUnit | Java Blog

Nach dem TDD-Ansatz implementieren wir eine Klasse, die korrekt รผbersetzt werden kann, aber bisher ohne Funktionalitรคt ist. ... 1.2.3 JUnit-Tests ausfรผhren.
Read more

Test-driven development JUnit-Test

Einleitung TDD Junit4 Beispiel Inhalt Test-driven Development (TDD) Junit4 Junit & eclipse TestCase TestSuite Die Assert Methoden
Read more

TDD Kata 1 - String Calculator - Osherove

TDD Kata 1. TDD Kata 2. TDD Kata 3 - Refactoring. Resources. Books I like. Tools. ... String Calculator. The following is a TDD Kata- an exercise in coding
Read more