exemplar icon indicating copy to clipboard operation
exemplar copied to clipboard

JUnit runners don't handle @Before nor @After

Open eskatos opened this issue 6 years ago • 5 comments

Using @RunWith(GradleSamplesRunner::class) or @RunWith(SamplesRunner::class)

Expected Behavior

@Before and @After functions to be invoked properly

Current Behavior

@Before and @After functions silently ignored

Context

I wanted to skip some samples under certain conditions in a @Before function using JUnit Assume. I didn't find a satisfying way so far.

@BeforeClass and @AfterClass are already handled by the parent ParentRunner.

eskatos avatar Feb 12 '19 17:02 eskatos

FWIW @Before and @After are handled in JUnit's BlockJUnit4ClassRunner.

marcphilipp avatar Feb 15 '19 07:02 marcphilipp

@Rule are also affected by this.

big-guy avatar Feb 20 '19 20:02 big-guy

@big-guy How so?

marcphilipp avatar Feb 21 '19 09:02 marcphilipp

@marcphilipp since we don't use BlockJUnit4ClassRunner, @Rule's are also ignored.

big-guy avatar Mar 01 '19 14:03 big-guy

Right, @ClassRule should work, though.

marcphilipp avatar Mar 01 '19 15:03 marcphilipp