It seems that this feature is in process of implementation in JUnit, but stalling. https://github.com/junit-team/junit/pull/605
JUnit / TestNG execute @BeforeXXX method before all tests having the same parameter
-
10-06-2023 - |
Question
I have the following problem:
I have a parameterized test
- it has a list of parameters
- it has several test methods
- test methods need a set up for each parameter
More detailed:
- for each file in list [...]
- parse file to several tables in db - [setUp]
- read data from tables - [setUp]
- and test data from each table in separate test - [tests]
I would like to execute setUp method and tests in such order
initialize parameters
for first parameter
- execute setUp method with first parameter
- execute all tests methods with first parameter
- for second parameter
- execute setUp method with second parameter
- execute all tests methods with second parameter
- ...
I tried JUnit and TestNG to do this and didn't find the solution. I would like to know if anyone knows how to do it.
I found a workaround for this in JUnit - place setUp and all test in one test method, and use ErrorCollector to make sure all check will be executed. But I don't like it because this way report is less clear.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow