英文:
java.lang.ExceptionInInitializerError in unit test for class genereted using WSDL
问题
我成功地调用了一个SOAP Web服务。现在,我正尝试编写一些单元测试,但是当测试访问使用WSDL生成的类(EmployeeInfo)时,会出现以下错误。
java.lang.ExceptionInInitializerError
at org.apache.axis.description.TypeDesc.<clinit>(TypeDesc.java:61)
at com.www.soapservice.schema.EmployeeInfo.<clinit>(EmployeeInfo.java:106)
我编写的单元测试如下
@RunWith(SpringRunner.class)
@SpringBootTest
public class RecordsManagerTests {
@Mock
private SoapClient soapClient;
@Test
public void sampletest() {
Mockito.when(soapClient.getFullEmployeeInfoById(Mockito.anyLong())).thenReturn(new EmployeeInfo());
RecordsManagerImpl sut = new RecordsManagerImpl(soapClient);
sut.getEmployeeInformation(999);
}
}
我搜索了这个问题,但只能找到模拟服务的解决方案。
英文:
I am consuming a SOAP web service successfully. Now, I am trying to write some unit tests but when the test access the class (EmployeeInfo) generated using WSDL then it is giving following error.
java.lang.ExceptionInInitializerError
at org.apache.axis.description.TypeDesc.<clinit>(TypeDesc.java:61)
at com.www.soapservice.schema.EmployeeInfo.<clinit>(EmployeeInfo.java:106)
The unit test I wrote is as follows
@RunWith(SpringRunner.class)
@SpringBootTest
public class RecordsManagerTests {
@Mock
private SoapClient soapClient;
@Test
public void sampletest() {
Mockito.when(soapClient.getFullEmployeeInfoById(Mockito.anyLong())).thenReturn(new EmployeeInfo());
RecordsManagerImpl sut = new RecordsManagerImpl(soapClient);
sut.getEmployeeInformation(999);
}
}
I searched for this issue but only could find mocking the service.
答案1
得分: 0
我不确定为什么它能够工作,但它确实可以,我在测试方法的开头添加了以下行并且它能够工作:
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
英文:
I am not sure why its working but it is, I added following line at the start of the test method and its working
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
专注分享java语言的经验与见解,让所有开发者获益!
评论