using @Rule TemporaryFolder inside @Before
See original GitHub issueI’m explaining the issue with a unit test:
public class TemporaryFolderTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Before
public void before(){
System.out.println(temporaryFolder.getRoot());
// fails
// assertNotNull(temporaryFolder.getRoot());
}
@Test
public void testTempFolder(){
System.out.println(temporaryFolder.getRoot());
assertNotNull(temporaryFolder.getRoot());
}
}
Issue Analytics
- State:
- Created 14 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
JUnit Rule TemporaryFolder - java - Stack Overflow
I've tried to create a new folder that is a child of the temp folder using tempFolder.newFolder("someFolder") in the @Before (setup) method of...
Read more >Using @Rule and TemporaryFolder - JUnit Tutorial - YouTube
Leverage the Rule annotation to neatly surround your unit tests with bespoke logic for setting up and tearing down components that can be ......
Read more >Create Temporary File/Folder using TemporaryFolder @Rule
The TemporaryFolder Rule allows creation of files and folders that should be deleted when the test method finishes (whether it passes or fails)....
Read more >Use JUnit Rule TemporaryFolder in Module
As database file i want to use a file within "TemporaryFolder" delivered by JUnit ... to be injected after @Before (the time junit...
Read more >Guide to JUnit 4 Rules - Baeldung
As we can see, we first define the TemporaryFolder rule tmpFolder. Next, our test method creates a file called test-file.txt in the temporary...
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
@lucasvc your problem appears to be https://github.com/powermock/powermock/issues/427 which is apparently fixed by https://github.com/powermock/powermock/pull/606
Alternatively use https://github.com/powermock/powermock/wiki/PowerMockRule
@kcooney really thanks for the links!