본문 바로가기

프로그래밍/Eclipse

Eclipse JUnit 사용하기

드디어 JUnit Test를 써보았다.

써봐야지 써봐야지 하면서 안쓰고 있다가..

써봤는데.. 참 이게 재미있기도 하고, 정말 유용한거 같더라.



우선 테스트케이스를 생성하고 싶은 프로렉트에 오른쪽 버튼을 누르고, JUnit 선택


사용자 삽입 이미지



그 후에 클래스 이름을 써주고, 아래 체크할수 있는 란에 보면, setUp(), tearDown() 에 체크를 하여,

오버라이딩을 해준다.


사용자 삽입 이미지


그리고 클래스가 만들어지면 메소드 이름을 테스트 하려는 메소드 이름앞에 test를 붙여준다.

ex) 테스트 하려는 메소드: removeNull
     JUnit  메소드 : testRemoveNull


그후 JUnit 의 테스트 메소드인 assertEquals 를 이용하여 메소드를 만든다.

실행은 단축키인 Alt + Shift + X , T 를 누르면 된다.

아래 예제 코드를 첨부한다.


[code type=java5]
import junit.framework.TestCase;

public class CommonUtilTest extends TestCase {

 CommonUtil commonUtil;

public static void main(String[] args) {
  junit.textui.TestRunner.run(CommonUtilTest.class);
 }

 protected void setUp() throws Exception {
  super.setUp();
 }

 protected void tearDown() throws Exception {
  super.tearDown();
 }

 /*
  * Test method for 'CommonUtil.removeNull(String)'
  */
 public void testRemoveNull() {
  assertEquals("parameter remove Null Return String",
      "Test Abc",
      commonUtil.removeNull("Test Abc"));
 }
[/code]

'프로그래밍 > Eclipse' 카테고리의 다른 글

Aptana Studio 1.0 릴리즈...  (0) 2007.12.10
Eclipse Properties Plug-In..  (0) 2007.10.02
MyEclipse LineNumber 설정...  (1) 2007.09.06
Unsupported major.minor version 49.0 error  (1) 2007.09.05
Eclipse JavaScript Plug-in 'aptana'..  (0) 2007.07.29