@Parameters method is executed before @ClassRule initialization. Could it be the way around?
See original GitHub issueI have the following problem (using junit 4.11):
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder();
...
@Parameters
public static Collection<Object[]> data() throws Exception {
return java.util.Arrays.asList(new Object[][] {
{0, tmp.getRoot().getPath()}
});
}
This results in initializationError
java.lang.IllegalStateException: the temporary folder has not yet been created
at org.junit.rules.TemporaryFolder.getRoot(TemporaryFolder.java:127)
So seems the @Parameters method is executed before the ClassRule initialization phase which makes scenarios like above one a bit complicated.
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Developers - @Parameters method is executed before @ClassRule ...
Parameters method is executed before @ClassRule initialization. Could it be the way around?
Read more >parameters method is executed before @beforeclass method
I would use just plain old java static {..} initializer instead of @BeforeClass, e.g.: @RunWith(Parameterized.class) public class ...
Read more >Guide to JUnit 4 Rules - Baeldung
We'll begin by introducing the JUnit Rules Model before walking through the most important base rules provided by the distribution.
Read more >Don't be lazy, use @Rules - Nicola Corti
In this way you can compose multiple helper classes and combine all the ... An Annotation to run a method before all the...
Read more >JGiven User Guide
JGiven can be used together with JUnit or TestNG, here we assume you ... Note that such methods are executed before the injection...
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
Current workaround:
It works but it needs that manual cleanup…
I tried something like this…
@RunWith(StepRunner.class) public class LaunchEnv { @ClassRule public static final CustomRunner tempFolder = new CustomRunner();
}
Call JUnitCore.runClasses(LaunchEnv.class); In the @Parameterized.Parameters method