getBoards 메소드 용 EasyMock으로 JUnit을 작성하는 방법 (아래 예 참조). EasyMock과 함께 JUnit을 사용하여 코드를 처리했지만 시도 할 수 없었습니다. 내가 잠시 당신이 조롱 할 예를 들어 무효 방법 조롱 사용 EasyMock.expectLastCall()
자바에서 easymock으로 junit을 작성하는 방법은 무엇입니까?
public class DCI implements ...{
private Device device = null;
private SnmpUtils snmp = null;
DCM(Device device){
this.device = device;
}
@override
void openCommun(){
snmp = new SnmpUtils(device);
snmp.openSnmpComm();
}
// ---> How to write Junit test with easymock for this method?
public List<Board> getBoards(DeviceIdn deviceIdn) throws SnmpException {
List<Board> boardList = new ArrayList<Board>();
try {
//BoardTableClass --> Below given
BoardTable boardTable = new BoardTable(snmp);
boardTable.readTable();
for (int row = 0; row < boardTable.size(); row++) {
String strBoardIndex = boardTable.getValue(row, BoardTable.BoardColumn.BoardIndex);
String strBoardName = boardTable.getValue(row, BoardTable.BoardColumn.BoardName);
String strBoardType = boardTable.getValue(row, BoardTable.BoardColumn.BoardType);
int boardIndex = new Integer(strBoardIndex);
BoardIdn boardIdn = new BoardIdn(deviceIdn, boardIndex);
Board board = new Board(boardIdn);
board.setName(strBoardName);
board.setType(strBoardType);
boardList.add(board);
}
logger.info(boardList.size());
}
//In handleException method , snmpException checked
catch (Exception e) {
handleException(e);
}
return boardList;
}
}
이 레이아웃은 모의에 도움이되지 않습니다. 인스턴스 변수를 구체적으로 작성중인 객체에 전달하고 있습니다. 인스턴스 변수를 조롱하고 싶지 않다면 조롱과는 거의 관련이 없습니다. – Makoto
안녕하세요. 하지만 여기에 모의 .. – shree