mockito+testng Mock HttpServletRequest
程序员文章站
2024-01-31 18:31:16
...
法2
org.springframework.mock.web.MockHttpServletRequest; org.springframework.mock.web.MockHttpServletResponse;
法1
package com.xxx.ttt;
import javax.servlet.http.HttpServletRequest;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.Test;
public class UUTest {
@Mock
private HttpServletRequest request;
@Test
public void test() {
MockitoAnnotations.initMocks(this);
Mockito.when(request.getAttribute("cc")).thenReturn("");
UUp = new UU(request);
Assert.assertEquals(p.getApp(), "uu");
}
}
上一篇: EasyMock让单元测试更"解耦"