question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using @Rule TemporaryFolder inside @Before

See original GitHub issue

I’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:closed
  • Created 14 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

0reactions
lucasvccommented, May 16, 2017

@kcooney really thanks for the links!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found