vitali_li
vitali_li

Reputation: 130

Run @Before method once for all tests in @ParameterizedTest for Junit5

I have several @ParameterizedTest test method in my class.

I have static @BeforeAll method which runs before all @ParameterizedTest test methods once.

Now I need a mechanism to run a certain '@Before' method before each @ParameterizedTest test method (NOT before each scenario of @ParameterizedTest test but before test method annotated as @ParameterizedTest).

The issue is that @BeforeEach annotation will run your 'before' method before each scenario of @ParameterizedTest test but I need to run that once.

Any ideas?

Upvotes: 2

Views: 956

Answers (1)

nishantvas
nishantvas

Reputation: 304

I have a similar problem, you can use @Nested for this

Link to answer

Junit Docs

Upvotes: 1

Related Questions