我有以下服务,我在其中使用 application.properties 文件的属性:
@Service
public class TesoSunSystemsServiceImpl implements TesoSunSystemsService {
@Value("${spring.sesame.proxy}")
private String proxySesame;
@Value("${spring.sesame.proxy.port}")
private Integer proxyPortSesame;
@Value("${sunSystem.usuario}")
private String usuario;
@Value("${sunSystem.contrasenia}")
private String contrasenia;
public String obtenerToken() throws Exception {
String body = "<soapenv:Envelope xmlns:soapenv=\"web=\"/\">\r\n" +
" <soapenv:Body>\r\n" +
" <web:SecurityProviderAuthenticateRequest>\r\n" +
" <web:name>" + usuario + "</web:name>\r\n" +
" <web:password>" + contrasenia + "</web:password>\r\n" +
" </web:SecurityProviderAuthenticateRequest>\r\n" +
" </soapenv:Body>\r\n" +
"</soapenv:Envelope>";
// Realiza la conexión al servicio SOAP
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxySesame, proxyPortSesame));
....
....
我的下一个测试证明了该方法:
@SpringBootTest
public class TesoSunSystemsServiceImplTest {
@InjectMocks
private TesoSunSystemsServiceImpl tesoSunSystemsServiceImpl;
@Test
void testGenerarFacturas(){
String Token = asfsaasfTokenTest;
String response = tesoSunSystemsServiceImpl.obtenerToken();
//Mas consideraciones, implementaciones, etc
assertNotNull(response);
}
如果您能给我一些如何继续的想法,提前致以问候和感谢。
对于单元测试,属性文件也必须放在
src/test/resources/
下。
相反,如果在测试过程中您需要使用另一个属性文件覆盖应用程序的属性,您可以在测试类之前使用注释
@TestPropertySource
。