В моем проекте Spring Boot с сообществом Intellij Idea я создаю интеграционные тесты с Junit и Mockito, я хочу установить переменные ENV во всем мире, потому что тесты представляют собой много точек выполнения, и в сообществе IntelliJ я могу установить их для каждой конфигурации. Я использую GNU/Linux, я устанавливаю переменные ENV в моем .BASHRC и поставляю файл, я определяю их в /тет/resources/application-test.yml . Когда я запускаю тесты, бросает исключение, потому что он не получает учетных данных DB, в данном случае от переменных ENV. Как он может прочитать значения, определенные в .bashrc ?
.bashrc
# Obviously I setted the values, are empty just to show you
export DB_URL_TEST=""
export DB_USERNAME_TEST=""
export DB_PASSWORD_TEST=""
< /code>
/test/resources/application-test.yml
spring:
datasource:
url: "${DB_URL_TEST}"
username: "${DB_USERNAME_TEST}"
password: "${DB_PASSWORD_TEST}"
driver-class-name: org.mariadb.jdbc.Driver
< /code>
The test in question:
// It's in development, it's I have
package com.latteIceCream.latte;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
public class FlavorCRUDTest {
@Autowired
MockMvc mockMvc;
@Test
public void flavorRequest() throws Exception
{
mockMvc.perform
(
MockMvcRequestBuilders.post("/flavor/{name}")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect
(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
);
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... boot-tests