소프트웨어 검증junit 5조dslab.konkuk.ac.kr/class/2010/10sv/practice/1... ·...

Post on 08-Sep-2020

0 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

소프트웨어 검증 발표 1

- JUnit -JUnit

5조200511350 장범석

BS&JWBS&JW

200511350 장범석200511330 서재원

JunitJunit이란이란??

JUnit은 자바 애플리케이션의 단위테스트 자동화를 위한 프레임워크JUnit은 자바 애플리케이션의 단위테스트 자동화를 위한 프레임워크

BS&JWBS&JW

단위단위(Unit)(Unit)테스트란테스트란??

BS&JWBS&JW

단위단위(Unit)(Unit)테스트란테스트란??

JUnitJUnit

BS&JWBS&JW

JunitJunit

BS&JWBS&JW

JunitJunit 사용법사용법 –– Test CaseTest Case

TestCase를 상속받아 클래스를 작성

Public class HelloWorld{public String getCurrentVersion(){

예제코드

public String getCurrentVersion(){return “version 1.0”;

}}

테스트코드

Import junit.framework.TestCase;

Public class HellowWorldTest extends TestCase{

li id t tG tC tV i (){puvlic void testGetCurrentVersion(){HelloWorld hw = new HelloWorld();assertEquals(hw.getCurrentVersion();

}}

BS&JWBS&JW

}

JunitJunit 사용법사용법 –– Test SuiteTest Suite

특정메소드만 실행

import junit.frame.work.Test;import junit.frame.work.TestCase;import junit.frame.work.TestSuite;

테스트코드

p j ;

public class HelloWorldTest extends TestCase{public void testGetCurrentVersion(){

HelloWorld hw = new HelloWorld();hi l h C i i 1 0this.assertEquals(hw.getCurrentVersion(), "version 1.0");

}public void testGetCurrentVersion2(){

HelloWorld hw = new HelloWorld();this asserEquals(hwgetCurrentVersion() "version 2 0");this.asserEquals(hw.getCurrentVersion(), version 2.0 );

}public HelloWorldTest(String method){

super(method);}}public static Test suite(){

TestSuite suite = new TestSuite();suite.addTest(new HelloWorldTest("testGetCurrentVersion2"));return suite();

BS&JWBS&JW

}}

JunitJunit 사용법사용법 –– Assertion Assertion 사용사용

메소드

assertEquals(primitive expected, primitive actual)

assertEquals(Object expected, Object actual)

assertSame(Object expected, Object actual)

assertNotSame(Object expected, Object actual)

assertNull(Object object)

assertNotNull(Object object)assertNotNull(Object object)

assertTrue(boolean condition)

assertFalse(boolean condition)( )

BS&JWBS&JW

JunitJunit 사용법사용법 –– SetUpSetUp과과 TearDownTearDown

BS&JWBS&JW

JunitJunit 사용법사용법 –– 예외처리예외처리

Fail()메소드 실행

import junit.frame.work*;

bli l E ti T t t d T tC {

테스트코드

public class ExceptionTest extends TestCase{public void testtestMyException(){

try{

throw new Exception(“your exception”);throw new Exception( your exception );}Catch( Exception e){

fail(“your exception”);y p}

}}

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

JunitJunit 사용법사용법 –– 통합된통합된 테스트테스트 환경환경

BS&JWBS&JW

BS&JWBS&JW

실전에는실전에는 얼마나얼마나 쓰일까쓰일까??실전에는실전에는 얼마나얼마나 쓰일까쓰일까??

BS&JWBS&JW

Geospatial Developer Survey

Utah GIS Portal. 2008

BS&JWBS&JW

why you were not doing more unit testingwhy you were not doing more unit testing.

BS&JWBS&JW

BS&JWBS&JW

Fail이다…..악!! 관련된 클래스가 100만개라니!!

Unit

BS&JWBS&JW

객체간의 의존성이 단위테스트의 가장 큰 적!!!

BS&JWBS&JW

예제코드

import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;...public class LogDailyAnalyzeJob {public class LogDailyAnalyzeJob {

public void analyze(String[] parameters) throws Exception {JobConf conf = new JobConf(LogDailyAnalyzeJob.class);...conf setJobName("LogDailyAnalyzer : " + parameters[0] +" for " + parameters[1]);conf.setJobName( LogDailyAnalyzer : + parameters[0] + for + parameters[1]);conf.setMapperClass(BasicMapper.class);conf.setCombinerClass(BasicCombiner.class);conf.setReducerClass(analyzer.getReducerClass());...String year = parameters[1].substring(0,4);String month = parameters[1].substring(4,6);String day = parameters[1].substring(6);String path = "/"+year+"/"+month+"/"+day;String path = / +year+ / +month+ / +day;conf.setInputPath(new Path("/user/statlogs" + path));conf.setOutputPath(new Path("/user/result" + path +"/"+parameters[0]+"/daily"));parameters[0]+ /daily ));...JobClient.runJob(conf);

}}

BS&JWBS&JW

}

단위테스트를 위해서 객체를 최대한 고립시켜야 한다.

BS&JWBS&JW

단위테스트를 위해서 객체를 최대한 고립시켜야 한다.

BS&JWBS&JW

BS&JWBS&JW

BS&JWBS&JW

BS&JWBS&JW

BS&JWBS&JW

top related