我正在尝试单元测试[使用Cucumber]以下代码库
a
我尝试了以How to test method Jsoup.connect (static) using PowerMock?
为灵感的以下解决方案final Connection connection = Jsoup.connect(PERFORMACE_TESTING_POST_URL);
connection
.followRedirects(false)
.method(Method.POST);
final org.jsoup.Connection.Response response = connection.execute();
final String ptJobLocation = response.header(HTTP_HEADER_LOCATION);
message = "Performance Testing Job Triggered. It is available at " + ptJobLocation;
但是我一直收到以下错误
//
// Mock the Jsoup mockConnection
//
final Connection mockConnection = Mockito.mock(Connection.class);
final Response mockResponse = Mockito.mock(Response.class);
PowerMockito.mockStatic(Jsoup.class);
//
// Mock jsoup connect
//
PowerMockito
.when(Jsoup.connect(Constants.PERFORMACE_TESTING_POST_URL))
.thenReturn(mockConnection);
//
// Mock connection.execute
//
Mockito
.when(mockConnection.execute())
.thenReturn(mockResponse);
//
// Mock header Retreival from Response
//
PowerMockito
.when(mockResponse.header(anyString()))
.thenReturn("Test Response");
对此有任何帮助将不胜感激。
使用的Libs如下