SetEnvironmentVariable and SetSystemProperty annotation cannot work in Junit 5
See original GitHub issueI write below test case, but it cannot work. Please help check it.
@Test
@SetEnvironmentVariable(key = "abc", value = "123")
public void testHandleRequest() {
// AlertAPIHandler apiHandler = new AlertAPIHandler();
assertEquals("123", System.getenv("abc"));
}
@Test
@SetSystemProperty(key = "Test", value = "123")
public void testSystemProperty() {
assertEquals("123", System.getProperty("Test"));
}
Below is my Gradle Settings:
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
testCompile group: 'org.junit-pioneer', name: 'junit-pioneer', version: '1.4.2'
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Properly set (system) properties in JUnit 5 - Stack Overflow
Both annotations work on the test method and class level, are repeatable as well as combinable. After the annotated method has been executed, ......
Read more >Allow simple expressions in SetEnvironmentVariables ...
would allow the SetEnvironmentVariables/SetSystemProperties annotations to dynamically resolve environment variable values from the runtime ...
Read more >Guide to the System Stubs Library - Baeldung
Learn the importance of being able to mock system resources and how System Stubs allows for complex configurations of stubbing with JUnit 4 ......
Read more >JUnit Pioneer 1.0 - nipafx.dev
Yesterday we released JUnit Pioneer 1.0 - here's a quick rundown ... (so i-klingon and xtg-x-cel-gaulish work) and both annotations work ...
Read more >SetEnvironmentVariable (junit-pioneer 1.5.0 API) - Javadoc.io
SetEnvironmentVariable is repeatable and can be used on the method and on the class level. If a class is annotated, the configured variable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Downgrading JUnit to 5.7.2 fixed the issue for me.
Running the following test:
With the following build / Maven config:
I wasn’t able to reproduce the errors described above.
Therefore, I will close this issue. Feel free to reopen/comment if the problem pops up again.