본문 바로가기
IT/JSP

[JSP] - 30. 이클립스에서 JUnit 단위 테스트 하는 방법

by 차이나는 개발자 2020. 8. 8.
728x90
반응형

#이클립스에서 JUnit 단위 테스트 하는 방법

-자바 프로그래밍 언어용 유닛 테스트 프레임워크이다

 

 

1. 프로젝트 우클릭 Other 클릭

 

 

2. JUnit Test Case 찾아서 클릭

 

 

3. 이름 + 기본적으로 생성할 메소드 선택 후 Finish

 

 

#DaoTest

package kr.ac.green.test;

import static org.junit.Assert.*;

import java.sql.Connection;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import kr.ac.green.dao.StudentDao;
import kr.ac.green.dto.Student;

public class DaoTest {

	private static StudentDao dao;
	private Connection con;
	
	// 제일 먼저 실행
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		dao = StudentDao.getDao();
	}
	
	// 테스트 직전 실행
	@Before
	public void setUp() throws Exception {
		con = dao.connect();
	}
	
	// 테스트 직후 실행
	@After
	public void tearDown() throws Exception {
		dao.disconnect(con);
	}
 
	// 테스트
	@Test
	public void testInsertInfo() {
		Student student = new Student(1,"kim","010-3334-3333",3,2);
		
		Assert.assertEquals(1, dao.insertInfo(con, student));
	}
	// 테스트
	@Test
	public void testSelectAll() throws Exception {
		Assert.assertEquals(7, dao.selectAll(con).length);
	}
	// 테스트
	@Test 
	public void testDeleteInfo(){
		int s_id = 1;
		Assert.assertEquals(1, dao.DeleteInfo(con, s_id));
	} 
	// 테스트
	@Test
	public void testUpdateInfo(){ 
		Student student = new Student(2,"0000","010-0000-0000", 0, 0);
		Assert.assertEquals(1, dao.UpdateInfo(con, student));
	}
	// 테스트
	@Test
	public void testSelectOne() throws Exception {
		int s_id = 5; 
		Assert.assertEquals(1, dao.selectOne(con, s_id));
	}
}

 

 

 

728x90
반응형

댓글