πŸ›οΈ HONGIKINGAN CMS Developer Manual

Version 202506 | Updated 2025-06-12
🌐 Language: πŸ‡°πŸ‡· ν•œκ΅­μ–΄ πŸ‡²πŸ‡³ Монгол πŸ‡ΊπŸ‡Έ English

9. πŸ§ͺ Testing & Debugging

9.1 eGovFrame Development Tools Introduction

The eGovFrame development tools are Eclipse-based Integrated Development Environment (IDE) that provides various features for HONGIKINGAN CMS development and testing.

9.1.1 Key Features of Development Tools

πŸ› οΈKey Features

  • Project Creation & Management: Create and manage eGovFrame-based projects
  • Code Templates: Provide standard code templates
  • Debugging Tools: Provide powerful debugging capabilities
  • Testing Tools: Support JUnit-based testing
  • Deployment Tools: Provide server deployment functionality

9.1.2 Development Tools Installation & Configuration

The eGovFrame development tools are provided based on Eclipse and can be installed as follows:

πŸ“₯ Download Development Environment

Download development environment from eGovFrame portal (www.egovframe.go.kr)

πŸ“‚ Extract Archive

Extract the downloaded file

πŸš€ Execute

Run Eclipse executable file (eclipse.exe)

9.2 Development Tools-Based Testing Methods

9.2.1 JUnit Test Writing & Execution

In eGovFrame, you can write and execute unit tests using JUnit.

Test Class Creation Method

🎯 Select Test Class

Right-click on the class to test > New > JUnit Test Case

βš™οΈ Configuration

Select test class name and methods to test

βœ… Creation Complete

Click Finish button to create test class

Test Code Writing Example

[Actual Code] JUnit Test Class Example

package humanframe.test.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import humanframe.backoffice.service.BbsService;
import humanframe.backoffice.vo.BbsVO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
    "classpath:humanframe/spring/context-common.xml",
    "classpath:humanframe/spring/context-datasource.xml",
    "classpath:humanframe/spring/context-mapper.xml"
})
public class BbsServiceTest {

    @Autowired
    private BbsService bbsService;
    
    @Test
    public void testSelectBbs() {
        // Execute test
        BbsVO bbs = bbsService.selectBbs(1);
        
        // Verify result
        assertNotNull(bbs);
        assertEquals(1, bbs.getBbsNo());
    }
}

Test Execution Method

🎯 Select Test

Right-click on test class or method

▢️ Execute

Select Run As > JUnit Test

πŸ“Š Check Results

Check test results in JUnit view (Green: Success, Red: Failure)

9.2.2 Test Coverage Analysis

You can analyze test coverage using the EclEmma plugin in Eclipse.

EclEmma Usage Method

🎯 Select Test

Right-click on test class or method

πŸ“Š Execute Coverage

Select Coverage As > JUnit Test

πŸ“ˆ Check Results

Check coverage results (Green: Covered, Red: Not covered, Yellow: Partially covered)

9.3 eGovFrame Debugging Methods

9.3.1 Debug Mode Execution

The method to run applications in debug mode in Eclipse is as follows:

πŸš€ Debug Execution

Right-click on project > Debug As > Debug on Server

πŸ–₯️ Server Selection

Select server and click Finish button

πŸ”„ Perspective Switch

Automatically switch to Debug perspective

9.3.2 Breakpoint Setting & Management

Breakpoint Setting Method

Breakpoint Types

🎯Breakpoint Types

  • Line Breakpoint: Stop execution at a specific line
  • Conditional Breakpoint: Stop execution only when specific conditions are met
    β†’ Right-click on breakpoint > Breakpoint Properties > Enter condition
  • Exception Breakpoint: Stop execution when specific exceptions occur
    β†’ Select Run > Add Java Exception Breakpoint

Breakpoint Management

9.3.3 Debugging Control Functions

The main functions for controlling execution in debug mode are as follows:

Function Shortcut Description
Resume F8 Execute until next breakpoint
Suspend - Suspend running thread
Terminate Ctrl+F2 Terminate debugging session
Step Into F5 Enter into method of current line
Step Over F6 Execute current line and move to next line
Step Return F7 Complete current method execution and return to caller
Drop to Frame - Return to the start of current stack frame

9.3.4 Variable & Expression Monitoring

Variable Value Checking

πŸ”Variable Checking Methods

  • Variables View: Display variable values in current scope
  • Expressions View: Evaluate user-defined expressions
    β†’ Click Add Watch Expression button to add expressions
  • Mouse Hover: Check values by hovering mouse over variables

Variable Value Modification

🎯 Select Variable

Select variable in Variables view

✏️ Change Value

Right-click > Change Value

βœ… Apply

Enter new value and click OK button

9.3.5 Stack Trace Analysis

Debug View Utilization

Stack Trace Analysis Method

πŸ“‹ Check Stack Trace

Check stack trace output in console view when exceptions occur

πŸ” Find Code Section

Find your code section in the stack trace

πŸ› Identify Problem

Navigate to that line to identify the cause of the problem

9.4 Logging & Log Analysis

9.4.1 eGovFrame Logging Configuration

eGovFrame implements logging using Log4j.

log4j.xml Configuration Example
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Console Output -->
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %5p [%c] %m%n" />
        </layout>
    </appender>
    
    <!-- File Output -->
    <appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="${LOG_PATH}/humanframe.log" />
        <param name="Append" value="true" />
        <param name="DatePattern" value="'.'yyyy-MM-dd" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %5p [%c] %m%n" />
        </layout>
    </appender>
    
    <!-- SQL Log -->
    <logger name="jdbc.sqlonly" additivity="false">
        <level value="INFO" />
        <appender-ref ref="console" />
        <appender-ref ref="file" />
    </logger>
    
    <!-- Application Log -->
    <logger name="humanframe" additivity="false">
        <level value="DEBUG" />
        <appender-ref ref="console" />
        <appender-ref ref="file" />
    </logger>
    
    <!-- Root Logger -->
    <root>
        <priority value="INFO" />
        <appender-ref ref="console" />
        <appender-ref ref="file" />
    </root>
</log4j:configuration>

Log Levels

Level Description
FATAL Critical error, application termination
ERROR Error, function execution failure
WARN Warning, potential issues
INFO Information, major events
DEBUG Debug information, detailed execution information
TRACE Most detailed information

9.4.2 Log Writing Methods

The method to write logs in code is as follows:

Log Writing Example
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BbsServiceImpl implements BbsService {

    private static final Logger logger = LoggerFactory.getLogger(BbsServiceImpl.class);
    
    @Override
    public BbsVO selectBbs(int bbsNo) {
        logger.debug("Board inquiry: bbsNo={}", bbsNo);
        
        try {
            BbsVO bbs = bbsDAO.selectBbs(bbsNo);
            logger.debug("Board inquiry result: {}", bbs);
            return bbs;
        } catch (Exception e) {
            logger.error("Error occurred during board inquiry: {}", e.getMessage(), e);
            throw e;
        }
    }
}

9.4.3 Log File Analysis in Eclipse

The method to analyze log files in Eclipse is as follows:

πŸ“‚ Open Log File

  • Select File > Open File menu
  • Select log file and click Open button

πŸ” Search Logs

  • Open search dialog with Ctrl+F shortcut
  • Enter search term and click Find button
  • Use regular expression search (e.g., ERROR|WARN)

πŸ”§ Log Filtering

  • Install log viewer plugins (LogViewer, EclipseLogViewer, etc.)
  • Filter by log level, time, message, etc.

9.5 SQL Query Debugging

9.5.1 MyBatis Log Configuration

The method to configure logs for debugging MyBatis queries is as follows:

log4jdbc Configuration

πŸ“¦ Add Dependency

Add dependency to pom.xml:

<dependency>
    <groupId>org.lazyluke</groupId>
    <artifactId>log4jdbc-remix</artifactId>
    <version>0.2.7</version>
</dependency>

πŸ”§ Change DataSource Configuration

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
    <property name="url" value="jdbc:log4jdbc:mysql://localhost:3306/humanframe"/>
    <property name="username" value="username"/>
    <property name="password" value="password"/>
</bean>

πŸ“ Add Logger to log4j.xml

<logger name="jdbc.sqlonly" additivity="false">
    <level value="INFO"/>
    <appender-ref ref="console"/>
</logger>
<logger name="jdbc.sqltiming" additivity="false">
    <level value="INFO"/>
    <appender-ref ref="console"/>
</logger>
<logger name="jdbc.audit" additivity="false">
    <level value="WARN"/>
    <appender-ref ref="console"/>
</logger>
<logger name="jdbc.resultset" additivity="false">
    <level value="WARN"/>
    <appender-ref ref="console"/>
</logger>
<logger name="jdbc.resultsettable" additivity="false">
    <level value="INFO"/>
    <appender-ref ref="console"/>
</logger>

9.5.2 SQL Map Debugging

The method to debug MyBatis SQL maps is as follows:

πŸ“„ Check SQL Map File

  • Open the corresponding SQL map file in src/main/resources/humanframe/sqlmap/ directory
  • Check SQL query syntax

πŸ” Check Parameters

  • Set breakpoints in debug mode
  • Check parameter values in Variables view

πŸ“‹ Check SQL Logs

  • Check executed SQL queries in console or log files
  • Check bound parameter values

πŸ”„ Check Result Mapping

  • Check mapping between result object fields and SQL result columns
  • Check type conversion errors

9.6 Common Errors & Solutions

9.6.1 Compilation Errors

πŸ”§Major Compilation Errors & Solutions

  • Class not found:
    β†’ Cause: Classpath issues or missing dependencies
    β†’ Solution: Right-click project > Maven > Update Project
  • Method not found:
    β†’ Cause: API changes or library version mismatch
    β†’ Solution: Check method signature and library version
  • Syntax error:
    β†’ Cause: Incorrect Java syntax
    β†’ Solution: Review and fix code

9.6.2 Runtime Errors

⚠️Major Runtime Errors & Solutions

  • NullPointerException:
    β†’ Cause: Null object reference
    β†’ Solution: Check object initialization and add null checks
  • ClassNotFoundException:
    β†’ Cause: Class loading failure
    β†’ Solution: Check classpath and add dependencies
  • SQLException:
    β†’ Cause: Database connection or query errors
    β†’ Solution: Check SQL queries and database connection settings

9.6.3 Web Application Errors

🌐Major Web Application Errors & Solutions

  • 404 Not Found:
    β†’ Cause: URL mapping errors or missing resources
    β†’ Solution: Check controller mapping and resource paths
  • 500 Internal Server Error:
    β†’ Cause: Server-side exceptions
    β†’ Solution: Check exception stack traces in log files and debug
  • 400 Bad Request:
    β†’ Cause: Invalid request parameters
    β†’ Solution: Validate and fix request parameters

9.7 Debugging Best Practices

9.7.1 Efficient Debugging Strategies

πŸ”„ Problem Reproduction

  • Find ways to consistently reproduce the problem
  • Document reproduction steps

πŸ“‹ Log Analysis

  • Check error messages and stack traces in log files
  • Adjust log levels to collect detailed information

🎯 Breakpoint Strategy

  • Set breakpoints near problem occurrence points
  • Use conditional breakpoints

πŸ”¬ Hypothesis Verification

  • Establish hypotheses about problem causes
  • Verify hypotheses through debugging

9.7.2 Debugging Tool Utilization Tips

πŸ’‘Debugging Tool Utilization Tips

  • Use Conditional Breakpoints:
    β†’ Set to break only under specific conditions
    β†’ Break only at specific iteration counts in loops
  • Use Watch Expressions:
    β†’ Evaluate complex expressions
    β†’ Monitor object states
  • Use Hot Code Replace:
    β†’ Apply code changes immediately in debug mode
    β†’ Test code changes without restarting debugging session
  • Thread Dump Analysis:
    β†’ Analyze deadlocks or performance issues
    β†’ Use Thread.getAllStackTraces() method
🎯

Testing & Debugging Key Points

  • Systematic Testing: Write unit tests using JUnit
  • Efficient Debugging: Problem solving through breakpoints and variable monitoring
  • Log Utilization: Track problems with appropriate log levels and messages
  • Tool Utilization: Use advanced features of eGovFrame development tools
  • Continuous Improvement: Improve code quality through debugging experience