原创

java 测试中不会读取 application.properties 值

温馨提示:
本文最后更新于 2024年04月12日,已超过 37 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

I have the following service, where I use the properties of my application.properties file:

@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));
     
    ....
    ....

I have my next test that proves that method :

@SpringBootTest
public class TesoSunSystemsServiceImplTest {    
    
    @InjectMocks
    private TesoSunSystemsServiceImpl tesoSunSystemsServiceImpl;
     
    @Test
    void testGenerarFacturas(){
     
        String Token = asfsaasfTokenTest;
            
        String response = tesoSunSystemsServiceImpl.obtenerToken();
     
        //Mas consideraciones, implementaciones, etc  
     
        assertNotNull(response);
        
    }
  • My question is, when I run my application, this makes use of the properties of the properties without any problem, but when I run the test errors appear as the test properties are not read and therefore to run the method with properties in null, this fails, how can I do for my service to read the properties of the properties when running the tests?

I would appreciate if you could give me some idea of how to proceed, greetings and thanks in advance.

正文到此结束
热门推荐
本文目录