java.lang.ExceptionInInitializerError在使用WSDL生成的类的单元测试中发生。

huangapple 未分类评论57阅读模式
英文:

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");

huangapple
  • 本文由 发表于 2020年4月6日 01:10:40
  • 转载请务必保留本文链接:https://java.coder-hub.com/61046373.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定