Jini's Blog

Ing...

  • Home
  • Business
    • Internet
    • Market
    • Stock
  • Parent Category
    • Child Category 1
      • Sub Child Category 1
      • Sub Child Category 2
      • Sub Child Category 3
    • Child Category 2
    • Child Category 3
    • Child Category 4
  • Featured
  • Health
    • Childcare
    • Doctors
  • Home
  • Business
    • Internet
    • Market
    • Stock
  • Downloads
    • Dvd
    • Games
    • Software
      • Office
  • Parent Category
    • Child Category 1
      • Sub Child Category 1
      • Sub Child Category 2
      • Sub Child Category 3
    • Child Category 2
    • Child Category 3
    • Child Category 4
  • Featured
  • Health
    • Childcare
    • Doctors
  • Uncategorized

JUNIT 테스트 작성 방법

 Jini     오전 1:44     JUNIT     No comments   

package com.jini.ch4;

import java.io.*;
import junit.framework.*;


public class FileReaderTester extends TestCase {
 
 private FileReader _input;
 private FileReader _empty;
 private static final String FILE_NAME = "c:/Users/jini/Desktop/data.txt";
 
 public static void main (String[] args) {
  //1. 기본적인 Test 실행 방식.
  junit.textui.TestRunner.run(suite());
  
  //2. 해당 클래스에서 test로 시작하는 모든 메소드를 테스트 하도록 함.
  junit.textui.TestRunner.run(new TestSuite(FileReaderTester.class));
  
  //3. 여러 클래스의 Test Suite를 연결하기 위한 MasterTester 클래스 방식/
  junit.textui.TestRunner.run( suite2());
 }

 public FileReaderTester(String name) {
  super(name);
 }
 
 /**
  * 메소드명을 파라미터로 하는 TestSuite 
  * @throws IOException
  */
 public static Test suite() {
  TestSuite suite = new TestSuite();
  suite.addTest(new FileReaderTester("testRead"));
  suite.addTest(new FileReaderTester("testReadAtEnd"));
  return suite;
 }
 
 public static Test suite2() {
  TestSuite result = new TestSuite();
  result.addTest(new TestSuite(FileReaderTester.class));
  result.addTest(new TestSuite(FileReaderTester.class));
  return result;
 }
 
 public void testRead() throws IOException {
  char ch = '&';
  for(int x = 0; x < 4; x++) {
   ch = (char)_input.read();
  }
  
  assertEquals('d', ch);
 }
 
 public void testReadAtEnd() throws IOException {
  int ch = -1234;
  for(int x = 0; x < 141; x++) {
   ch = _input.read();
  }
  
  assertEquals("read at end", -1, _input.read());
 }
 
 public void testReadBoundaries() throws IOException {
  assertEquals("read first char", 'B', _input.read());
  int ch;
  for(int x = 0; x < 140; x++) {
   ch = _input.read();
  }
  
  assertEquals("read last char", '6', _input.read());
  assertEquals("read at end", -1, _input.read());
  assertEquals("read past end", -1, _input.read());
 }
 
 public void testEmptyRead() throws IOException {
  assertEquals(-1, _empty.read());
 }
 
 public void testReadAfterClose() throws Exception {
  _input.close();
  
  try {
   _input.read();
   fail("read past end에 예외가 발생하지 않음");
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
 
 protected void setUp() {
  try {
   _input = new FileReader(FILE_NAME);
   _empty = newEmptyFile();
  } catch (IOException e) {
   throw new RuntimeException(e.toString());
  }
 }
 
 protected void tearDown() {
  try {
   _input.close();
  } catch (IOException e) {
   throw new RuntimeException("테스트 파일을 닫는 중 에러 발생");
  }
 }
 
 private FileReader newEmptyFile() throws IOException {
  File empty = new File(FILE_NAME);
  FileOutputStream out = new FileOutputStream(empty);
  out.close();
  return new FileReader(empty);
 }
}

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
이메일로 전송BlogThis!X에 공유Facebook에서 공유
최근 게시물 이전 게시물 홈

0 Comments:

댓글 쓰기

Popular Posts

  • WebFlux Error Handling
    WebFlux Error Handling doOnError : 예외 발생시 특정행위를 수행한다. onErrorReturn : 예외 발생시 특정 값을 return 한다. onErrorResume : 예외 발생시 다른 Flux형태로 return 한다....
  • 문법에서 문장까지(관사/무관사)
    1. 관사 ■ 부정관사 A/An 1) 하나임을 표시 2) 어떤 / 어느정도 3) 직업 앞에 쓰여 사람의 소속 표시(Categorization) 4) 대표단수 -> 일반화(Categorization) 5) 단수 가산 명사를...
  • 윈도우(Window)에서 사용 포트 확인 및 프로세스 KILL
    1. 특정포트가 열려있는지 확인 - netstat -na | findstr "포트" 2. 열려 있는 포트의 PID 확인 - netstat -nao | findstr "포트" 3. PID 찾기 - task...
  • Redmine Text Format
    1. 글자색상 변경 %{color:red}dev% 2. 음영색상 변경 %{background:lightgreen} lightgreen% 3. 문단 넘버링(띄어쓰기 주의) # 큰 제목 ## 큰제목의 하위 제목 # 두번째 큰 제목 # ...
  • JUNIT 테스트 작성 방법
    package com.jini.ch4; import java.io.*; import junit.framework.*; public class FileReaderTester extends TestCase { private FileReader ...

Recent Posts

Recent Posts Widget

Blog Archive

  • ►  2023 (4)
    • ►  3월 (1)
    • ►  2월 (1)
    • ►  1월 (2)
  • ►  2022 (1)
    • ►  2월 (1)
  • ►  2020 (8)
    • ►  7월 (1)
    • ►  4월 (3)
    • ►  3월 (4)
  • ►  2018 (1)
    • ►  7월 (1)
  • ►  2015 (1)
    • ►  5월 (1)
  • ►  2014 (5)
    • ►  8월 (1)
    • ►  7월 (1)
    • ►  6월 (1)
    • ►  5월 (1)
    • ►  1월 (1)
  • ▼  2013 (10)
    • ►  12월 (1)
    • ▼  11월 (1)
      • JUNIT 테스트 작성 방법
    • ►  9월 (2)
    • ►  8월 (3)
    • ►  7월 (3)
  • ►  2012 (1)
    • ►  3월 (1)

Categories

  • 객체지향 (1)
  • 도서요약 (1)
  • 문법에서 문장까지 (2)
  • 일상 (1)
  • 자기계발 (1)
  • 책 (1)
  • 키보드 (1)
  • 키크론 (1)
  • blogspot (2)
  • error (1)
  • exception (1)
  • GIT (1)
  • JAVA (6)
  • JUNIT (1)
  • K8 PRO RGB (1)
  • kafka (1)
  • markdown (1)
  • mongodb (2)
  • mongotemplate (1)
  • optional (1)
  • Oracle (4)
  • Redmine (1)
  • spring (1)
  • stackedit (1)
  • troubleshooting (1)
  • Visual Studio (1)
  • Webflux (1)

Unordered List

Pages

  • 홈

Text Widget

Categories

Tags

Facebook

  • Home
  • Features
  • _Multi DropDown
  • __DropDown 1
  • __DropDown 2
  • __DropDown 3
  • _ShortCodes
  • _SiteMap
  • _Error Page
  • Documentation
  • Video Documentation
  • Download This Template

Footer Menu Widget

  • Home
  • About
  • Contact Us

Social Plugin

JINI. Powered by Blogger.

Copyright © Jini's Blog | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates