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
[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
- Double-click on the left margin of the line where you want to set a breakpoint in the code editor
- Or right-click on the line > Toggle Breakpoint
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
- Enable/Disable Breakpoint: Right-click on breakpoint > Enable/Disable
- Remove Breakpoint: Right-click on breakpoint > Remove
- View All Breakpoints: Window > Show View > Breakpoints
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
- Display currently running threads and stack traces
- Double-click stack frame to navigate to that location
- Check thread status (running, suspended, terminated, etc.)
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.
<?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:
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