Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inject JUnit 5 parameters into @BeforeEach

I'm currently writing some parameterized tests with JUnit 5 (using @EnumSource).

I'm trying to run a method before each test using the same parameter as the test itself, but JUnit fails with No ParameterResolver registered for parameter [...enum] in method [...beforeEach].

Is there a way to achieve this, or should I just make a private method to call at the beginning of each test?

like image 499
Klemen Košir Avatar asked Jan 20 '26 08:01

Klemen Košir


1 Answers

It looks like this is not currently possible.

I resolved this by calling a method with test parameters at the beginning of each test.

like image 199
Klemen Košir Avatar answered Jan 23 '26 01:01

Klemen Košir