easymock简单示例

easyMock代码示例:

package test.mock;

import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;

import org.easymock.EasyMock;
import org.easymock.internal.MocksControl;
import org.junit.Test;

public class FirstMock {
	 @Test
	 public void testMock() {
	  HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
	  request.getParameter("ffff");
	  EasyMock.expectLastCall().andReturn("xxxx").times(2);
	  EasyMock.expect(request.getParameter("ffff")).andReturn("33333");
	  EasyMock.expect(request.getRealPath("/")).andReturn("fffffffff").anyTimes();
	  //EasyMock.expectLastCall().andReturn("ffff").times(1);
	  EasyMock.replay(request);
	  System.out.println(request.getParameter("ffff"));
	  System.out.println(request.getParameter("ffff"));
	  System.out.println(request.getParameter("ffff"));
	  System.out.println(request.getRealPath("/"));
	  EasyMock.verify(request);
	 }


}

 

你可能感兴趣的:(sql,servlet,JUnit)