// JUnit
- 단위 테스트 도구
package com.test.di04;
public interface BoardDAO {
void list();
}
package com.test.di04;
public class BoardDAOImpl implements BoardDAO{
@Override
public void list() {
System.out.println("select * from tblBoard");
}
}
package com.test.di04;
public interface BoardService {
void list();
}
package com.test.di04;
public class BoardServiceImpl implements BoardService {
private BoardDAO dao;
public void setDao(BoardDAO dao) {
this.dao = dao;
}
@Override
public void list() {
//목록 가져오기
//BoardDAO dao = new BoardDAOImpl();
//dao.list();
this.dao.list();
}
}
package com.test.di04;
import org.springframework.beans.factory.annotation.Autowired;
public class BoardController {
//의존 주입 도구
//1. 생성자
//2. Setter
private BoardService service;
@Autowired
public BoardController(BoardService service) {
this.service = service;
}
//list.do
public void doGet() {
//BoardController > (의존) > BoardService > (의존) > BoardDAO
//객체 생성 순서
//1. BoardController
//2. BoardService
//3. BoardDAO
//의존 객체
//BoardService service = new BoardServiceImpl();
//service.list();
this.service.list();
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
@Log4j
public class XMLTest {
@Autowired
private BoardController controller;
@Test
public void testController() {
// 통과여부
assertNotNull(controller);
controller.doGet();
}
}
'서버 > Spring' 카테고리의 다른 글
[스프링(Spring)] MVC 에러 처리 (0) | 2023.06.16 |
---|---|
[스프링(Spring)] MVC 데이터 수신 및 전송 (1) | 2023.06.15 |
[스프링(Spring)] AOP (1) | 2023.06.15 |
[스프링(Spring)] DI, IoC (0) | 2023.06.14 |
[스프링(Spring)] 환경설정 (0) | 2023.06.13 |