Wie man system.getenv () mit junit5 verspottetJava

Java-Forum
Anonymous
 Wie man system.getenv () mit junit5 verspottet

Post by Anonymous »

Ich möchte das System.getenv () -Methode verspotten. Ich habe nur Lösungen für JUNIT4 und PowerMockito gefunden.
Ich verwende die folgende Abhängigkeit: < /p>

Code: Select all

    
org.mockito
mockito-junit-jupiter
2.23.0
test

< /code>
Hier ist mein Beispiel für den Test: < /p>
@ExtendWith(MockitoExtension.class)
public class TestEnvVariable {

@Mock
System system;

@Test
public void shouldExpandPropertyContentToMatchingSysEnv() throws Exception {
when(system.getenv("KEY")).thenReturn("VALUE");
assertEquals("VALUE", "KEY");
}
}
Wie kann ich System.getenv () mit junit5?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post