• 개발환경
  • 실행환경
  • 실행환경 예제
  • 공통컴포넌트
개발환경 실행환경 실행환경 예제 공통컴포넌트
  • 소개
  • 설치 가이드
  • 구현 도구
  • 테스트 도구
  • 배포 도구
  • 형상 관리 도구
  • 구성 가이드
  • 활용 가이드
  • 운영 가이드
소개
  • 개발프레임워크 개발환경 소개
  • 개발자 개발환경 소개
  • 서버 개발환경 소개
설치 가이드
  • 개발자 개발환경 설치가이드
  • 서버 개발환경 4.3.0 설치가이드
  • 개발환경 Getting Started
  • Implementation Tool 수동 설치가이드
구현 도구
    Editor
    • Batch IDE
    • UML Editor
    • DBIO Editor
    • Code Genetation
    • Code Inspection
    • Server Connection Management
  • Debug
테스트 도구
    Unit Test
    • Test Case
    • Mock Support
    • DB Support
    • MVC Test
    Test Automation
    • Write TestSuite
    • Run TestSuite
    • Test Reporting
  • Test Coverage
  • Batch Job Test Wizard
  • SpotBugs
  • 참조 문서 목록
    • egovframework-dev-tst-ant 프로젝트 소스 코드
    • egovframework-dev-tst 프로젝트 소스 코드
    • 테스트 결과 Excel 리포트
    • 테스트 결과 Excel 리포트 상세
    • Maven에서 생성한 테스트 결과 HTML 리포트
    • Unit Test 작성을 위한 pom.xml dependency 설정
    • 이클립스에서 Ant 실행하기
    • 이클립스에서 Maven 실행하기
    • 엑셀 리포팅 사용을 위한 setting.xml 설정
    • Ant에서 생성한 테스트 결과 HTML 리포트
    • EMMA 실행을 위한 pom.xml 설정 샘플
    • EMMA 실행을 위한 build.xml 설정 샘플
    • EMMA에서 생성한 HTML 리포트 샘플
배포 도구
    Build Tool
    • Maven

        Maven

        • 빌드 Lifecycle
        • 빌드 레퍼지토리
        • 구현도구 플러그인(m2eclipse)
    • Gradle

        Gradle

        • 구현도구 플러그인(Buildship)
        • 표준프레임워크 Sample 프로젝트를 Gradle로 빌드환경 전환
        • 표준프레임워크 Boot Sample 프로젝트를 Gradle로 빌드환경 전환
    • 통합빌드
    • Docker

        Docker

        • Docker Tooling
    • Nexus
  • 서버 이관
형상 관리 도구
    Configuration Management
    • 서버환경 운영
    • 클라이언트환경 사용
    Change Management
    • 이슈관리
    • 이슈검색
    • 대시보드
    • 스페이스관리
    • 사용자관리
    • 통계
    • 설정관리
구성 가이드
  • 구성 가이드
활용 가이드
    운영 가이드
    • 운영 가이드
    페이지보기 페이지편집 문서에 이슈 생성 프로젝트에 이슈 생성

    개발환경

      • 개발프레임워크 개발환경 소개
      • 개발자 개발환경 소개
      • 서버 개발환경 소개
      • 개발자 개발환경 설치가이드
      • 서버 개발환경 4.3.0 설치가이드
      • 개발환경 Getting Started
      • Implementation Tool 수동 설치가이드
        • Batch IDE
        • UML Editor
        • DBIO Editor
        • Code Genetation
        • Code Inspection
        • Server Connection Management
      • Debug
        • Test Case
        • Mock Support
        • DB Support
        • MVC Test
        • Write TestSuite
        • Run TestSuite
        • Test Reporting
      • Test Coverage
      • Batch Job Test Wizard
      • SpotBugs
        • egovframework-dev-tst-ant 프로젝트 소스 코드
        • egovframework-dev-tst 프로젝트 소스 코드
        • 테스트 결과 Excel 리포트
        • 테스트 결과 Excel 리포트 상세
        • Maven에서 생성한 테스트 결과 HTML 리포트
        • Unit Test 작성을 위한 pom.xml dependency 설정
        • 이클립스에서 Ant 실행하기
        • 이클립스에서 Maven 실행하기
        • 엑셀 리포팅 사용을 위한 setting.xml 설정
        • Ant에서 생성한 테스트 결과 HTML 리포트
        • EMMA 실행을 위한 pom.xml 설정 샘플
        • EMMA 실행을 위한 build.xml 설정 샘플
        • EMMA에서 생성한 HTML 리포트 샘플
        • Maven
          • 빌드 Lifecycle
          • 빌드 레퍼지토리
          • 구현도구 플러그인(m2eclipse)
        • Gradle
          • 구현도구 플러그인(Buildship)
          • 표준프레임워크 Sample 프로젝트를 Gradle로 빌드환경 전환
          • 표준프레임워크 Boot Sample 프로젝트를 Gradle로 빌드환경 전환
        • 통합빌드
        • Docker
          • Docker Tooling
        • Nexus
      • 서버 이관
        • 서버환경 운영
        • 클라이언트환경 사용
        • 이슈관리
        • 이슈검색
        • 대시보드
        • 스페이스관리
        • 사용자관리
        • 통계
        • 설정관리
      • 구성 가이드
        • 운영 가이드
      1. Home
      2. 개발환경
      3. 테스트 도구
      4. 참조 문서 목록
      • 페이지 보기
      • 페이지 편집
      • 문서에 이슈 생성
      • 프로젝트에 이슈 생성

      이 페이지의 구성

      egovframework-dev-tst 프로젝트 소스 코드

      • egovframework-dev-tst 프로젝트 소스 코드
        • JUnit Test XML 파일 예
        • Report VO 클래스
        • TestSuiteXmlParser
        • JUnitReportParser
        • EgovJUnitExcelReportGenerator
        • EgovExcelUtil

      egovframework-dev-tst 프로젝트 소스 코드

      egovframework-dev-tst 프로젝트는 JUnit Test XML 파일을 파싱하고, 템플릿 엑셀 파일을 읽어 들여, 해당값을 매핑한 후 엑셀 형식 리포트로 생성하는 주요 작업을 구성하는 라이브러리이다. 여기에서는 소스 코드에 대한 설명을 하도록 하고, 자세한 내용은 API 문서나 소스를 직접 참조하기 바란다.

      JUnit Test XML 파일 예

      <?xml version="1.0" encoding="UTF-8" ?>
      <testsuite errors="0" skipped="1" tests="6" time="3.359" failures="0" name="egovframework.dev.tst.report.junit.JUnitExcelReportGeneratorTest">
        <properties>
          <property value="Sun Microsystems Inc." name="java.vendor"/>
          <property value="C:\Documents and Settings\juroh\.m2\repository" name="localRepository"/>
         . . . . 중략 . . . .
        </properties>
        <testcase classname="egovframework.dev.tst.report.junit.JUnitExcelReportGeneratorTest" time="0.594" name="testNonXmlReportFileListException"/>
        <testcase classname="egovframework.dev.tst.report.junit.JUnitExcelReportGeneratorTest" time="0" name="testNotExistXmlReportFileListException"/>
        <testcase classname="egovframework.dev.tst.report.junit.JUnitExcelReportGeneratorTest" time="0" name="testNonOutputDirException"/>
        <testcase classname="egovframework.dev.tst.report.junit.JUnitExcelReportGeneratorTest" time="0" name="testNotExistOutputDirException"/>
        <testcase classname="egovframework.dev.tst.report.junit.JUnitExcelReportGeneratorTest" time="0.016" name="testGenerateExcelDefault">
          <skipped/>
        </testcase>
        <testcase classname="egovframework.dev.tst.report.junit.JUnitExcelReportGeneratorTest" time="2.609" name="testGenerateExcelFile"/>
      </testsuite>
      

      Report VO 클래스

      • ReportTestCase는 위 XML에서 <testcase> 태그 정보를 하나씩 담는다.
      • ReportTestSuite는 위 XML에서 <testsuite> 태그의 요약 정보를 담는다.

      TestSuiteXmlParser

      JUnit Test XML 파일을 파싱하는 <strong>TestSuiteXmlParser</strong> 클래스에 대해 알아보자.

      TestSuiteXmlParser 클래스는 SAX 파서를 이용하여 XML을 파싱한다. 클래스의 구조는 다음과 같으며, org.xml.sax.helpers.DefaultHandler 클래스의 메소드 중 필요한 부분을 구현하면 된다.

      Super Class

      • org.xml.sax.helpers.DefaultHandler를 상속받는다.
        public class TestSuiteXmlParser extends DefaultHandler {
         . . .
        }
        

      Methods

      • <strong>Collection parse(String xmlPath)</strong> 대상 XML 파일 Full Path을 입력받아 XML 파싱을 하여 ReportTestCase와 ReportTestSuite 객체에 정보를 담는다. JUnitReportParser가 호출한다.

            public Collection parse(String xmlPath) throws ParserConfigurationException, SAXException, IOException {
                SAXParserFactory factory = SAXParserFactory.newInstance();
         
                SAXParser saxParser = factory.newSAXParser();
         
                classesToSuites = new HashMap();
         
                saxParser.parse(new File(xmlPath), this);
         
                if (currentSuite != defaultSuite) {
                    // defaultSuite
                    if (defaultSuite.getNumberOfTests() == 0){
                        classesToSuites.remove(defaultSuite.getFullClassName());
                    }
                }
                return classesToSuites.values();
            }
        

        ✔ 사용 예는 TestCase(TestSuiteXmlParserTest)를 통해 확인할 수 있다.

      • 기타

        • void startElement(String uri, String localName, String qName, Attributes attributes) : 시작 태그에 대한 처리 부분을 담고 있다.
        • void endElement(String uri, String localName, String qName) : 끝 태그에 대한 처리 부분을 담고 있다.
        • void characters(char ch[], int start, int length) : element 내의 문자 데이터 처리에 대한 로직
        • private List parseCause(String detail) : Fail 원인에 대한 처리를 위해 내부적으로 사용하는 메소드
        • private List parseCause(String detail, String compareTo) : Fail 원인에 대한 처리를 위해 내부적으로 사용하는 메소드

      JUnitReportParser

      JUnitReportParser는 파싱한 XML 정보를 담고 있는 ReportTestCase와 ReportTestSuite을 이용하여 리포팅에 필요한 정보로 재조정한다.

      Fields

      JUnit Test XML 파일 Full Path 목록과, TestSuite List를 사용한다.

          /** JUnit Test XML 파일 Full Path 목록 */
          List<File> xmlReportFileList;
       
          /** TestSuite 목록 */
          List<ReportTestSuite> testSuites = new ArrayList<ReportTestSuite>();
      

      Methods

      • <strong>List parseXMLReportFiles()</strong> - JUnit Test XML 파일을 파싱하는 메인 함수

        public List parseXMLReportFiles() throws EgovTestException {
            Collection suites = null;
         
            if (xmlReportFileList != null && xmlReportFileList.size() > 0) {
         
                TestSuiteXmlParser parser = new TestSuiteXmlParser();
                for (int idx = 0; idx < xmlReportFileList.size(); idx++) {
                    File currentReport = (File) xmlReportFileList.get(idx);
         
                    try {
                        suites = parser.parse(currentReport.getAbsolutePath());
                    } catch (. . .) { . . .}
         
                    testSuites.addAll(suites);
                }
            }
         
            return testSuites;
        }
        

        ✔ 사용 예는 TestCase(JUnitReportParserTest)에서 확인할 수 있다.

      • 기타

        • Map getSummary(List suites) : ReportTestSuite으로부터 전체 Summary 정보를 모은다.
        • Map getSuitesGroupByPackage(List testSuitesList) : ReportTestSuite으로부터 패키지별 요약 정보를 모은다.
        • computeSuccessRate(int tests, int errors, int failures, int skipped) : 성공률을 백분률로 계산한다.

      EgovJUnitExcelReportGenerator

      Fields

      • XML로부터 테스트 결과 정보를 갖기 위한 정보
            /** JUnit XML Parser */
            private JUnitReportParser parser;
         
            /** JUnit Test XML 파일 Full Path 목록 */
            List<File> xmlReportFileList;
         
            /** Test Suite Lists */
            private List<ReportTestSuite> testSuites;
        
      • 엑셀 파일 생성을 위해 필요한 정보
            /** Excel 리포트의 템플릿 리포트 파일의 Full Path */
            private File templatePath;
         
            /** Excel 파일이 작성될 디렉토리 위치 */
            private File outputDirectory;
         
            /** Excel 리포트 파일명 */
            private String outputName;
        
      • POI의 엑셀 처리 관련 객체 - 엑셀 파일 정보
            /** ExtenXLS object representing MS Excel Document */
            private HSSFWorkbook book;
        
      • 템플릿 엑셀 파일의 각 헤더 위치 정보
            /** Summary 헤더 위치 정보 */
            private int[] summaryPosInfos = { 0, 0, 3 }; // sheet, col, row
         
            /** Package 헤더 위치 정보 */
            private int[] packagePosInfos = { 0, 0, 7 }; // sheet, col, row
         
            /** TestCase Lists 헤더 위치 정보 */
            private int[] listsPosInfos = { 1, 0, 3 }; // sheet, row, col
        
      • 템플릿 엑셀 파일의 헤더 위치 정보를 담고 있는 Array의 인덱스 상수
            /** Sheet 정보 IDX_SHEET */
            public final static int IDX_SHEET = 0;
         
            /** Column 정보 IDX_COL */
            public final static int IDX_COL = 1;
         
            /** Row 정보 IDX_ROW */
            public final static int IDX_ROW = 2;
        

      Constructor

      생성자에서 입력 받아야 하는 정보는 다음과 같다.

          /**
           * 생성자
           * 
           * @param xmlReportFileList JUnit Test XML 파일의 Full Path List
           */
          public EgovJUnitExcelReportGenerator(List<File> xmlReportFileList)
          {
              this.xmlReportFileList = xmlReportFileList;
          }
       
          /**
           * 생성자
           * 
           * @param xmlReportFileList JUnit Test XML 파일의 Full Path List
           * @param templatePath 템플릿 엑셀 파일 객체
           * @param outputDirectory 파일 생성 위치 객체
           * @param outputName 생성될 엑셀 파일 명
           */
          public EgovJUnitExcelReportGenerator(List<File> xmlReportFileList,
                  File templatePath, File outputDirectory, String outputName)
          {
              this.xmlReportFileList = xmlReportFileList;
              this.templatePath = templatePath;
              this.outputDirectory = outputDirectory;
              this.outputName = outputName;
          }
      

      EgovExcelUtil

      엑셀 파일 읽어서 Workbook 생성하기

      템플릿 엑셀 파일을 읽어 Workbook을 생성하는 방법은 EgovExcelUtil 클래스의 readExcelFile 메소드에서 담당한다.

          public static HSSFWorkbook readExcelFile(File xlsFullPath) throws EgovTestException {
              POIFSFileSystem fs = null; // POI FileSystem
              HSSFWorkbook wb = null; // HSSFWorkbook 엑셀 Workbook
       
              try {
                  FileInputStream fis = new FileInputStream(xlsFullPath);
                  fs = new POIFSFileSystem(fis);
                  wb = new HSSFWorkbook(fs);
              } catch (...) { . . . }
              return wb;
          }
      

      엑셀파일 저장

      엑셀 파일로 저장하는 기능은 writeExcelReport 메소드에서 담당한다.

          public static void writeExcelReport(File fullPath, HSSFWorkbook wb) {
              FileOutputStream fos = null;
              try {
                  fos = new FileOutputStream(fullPath);
                  wb.write(fos);
                  fos.close();
              } catch (...) { . . . }
          }
      

      Cell에 값을 세팅

      Cell은 엑셀 파일의 Sheet 내에서 column과 row 값을 갖는 단위를 말한다. Cell에 값을 세팅하는 기능은 setCellValues에서 담당한다.

          public static void setCellValues(HSSFRow row, List values, int startColumn, HSSFRow startRow) {
              HSSFCellStyle style = null;
              HSSFCell cell = null;
              HSSFCell startCell = null;
       
              int currentColumn = startColumn;
       
              for (int index = 0; index < values.size(); index++) {
                  cell = row.getCell(currentColumn);
       
                  if (cell == null) {
                      cell = row.createCell(currentColumn);
                  }
       
                  setCellValue(cell, values.get(index));
       
                  // Style을 세팅한다.
                  if (startRow != null) {
                      startCell = startRow.getCell(currentColumn);
                      if (startCell != null) {
                          style = startCell.getCellStyle();
                          cell.setCellStyle(style);
                      }
                  }
       
                  currentColumn++;
              }
          }
       
          public static void setCellValues(HSSFRow row, int currentCol, Object value) {
              HSSFCell cell = null;
       
              if (value != null) {
                  cell = row.getCell(currentCol);
       
                  if (cell == null) {
                      cell = row.createCell(currentCol);
                  }
       
                  setCellValue(cell, value);
              }
          }
       
          public static void setCellValue(HSSFCell cell, Object value) {
              if (value != null) {
                  if (value instanceof String) {
                      cell.setCellValue(new HSSFRichTextString((String) value));
       
                  } else if (value instanceof Integer) {
                      cell.setCellValue((Integer) value);
       
                  } else if (value instanceof Double) {
                      cell.setCellValue((Double) value);
       
                  } else if (value instanceof Float) {
                      cell.setCellValue((Float) value);
                  }
              }
          }
      
      • 대표전화  1566-3598 (070-4448-2678)
      • 대표문의메일  egovframesupport@gmail.com
      전자정부 표준프레임워크 Git
      이용 안내 라이센스

      COPYRIGHT (C) 2024 eGovFramework. ALL RIGHTS RESERVED.