How to autowire field in static @BeforeClass?

With Junit 5 you can do this (@BeforeAll instead of @BeforeClass)

public void ITest {
    private EntityRepository dao;

    public static void init(@Autowired EntityRepository dao) {; //possible now as autowired function parameter is used

By leaving the field it means it can be used in other tests

Leave a Comment