Wie importiere ich Env -Variablen aus Linux -Shell in Spring -Boot -Tests?Linux

Linux verstehen
Anonymous
 Wie importiere ich Env -Variablen aus Linux -Shell in Spring -Boot -Tests?

Post by Anonymous »

In meinem Spring Boot -Projekt mit Intellij Idea Community erstelle ich Integrationstests mit Junit und Mockito, ich möchte Env -Variablen global festlegen, da Tests viele Ausführungspunkte sind, und in der Intellij -Community kann ich sie für jede Run -Konfiguration festlegen. Ich verwende Gnu/Linux, ich habe die Env-Variablen in meinem .bashrc festgelegt und die Datei bezieht. Ich definiere sie in /test/resources/application-test.yml . Wenn ich die Tests ausführe, löst eine Ausnahme aus, da die DB -Anmeldeinformationen in diesem Fall nicht aus den Env -Variablen erhalten. Wie kann es die in .bashrc ?
definierten Werte lesen

Code: Select all

.bashrc

Code: Select all

# 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

Code: Select all

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)

);

}

}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post