Home > AI > Backend > SpringBoot >

@BeforeEach

It works with @SpringBootTest

@Autowired needs to be under @SpringBootTest to get worked

Example

@Slf4j
@SpringBootTest
public class TestSpringBoot {

    private List<String> list;

    @BeforeEach
    public void init() {
        log.info("[Shark] startup-springboot");
        list = new ArrayList<>(Arrays.asList("test1", "test2"));
    }

    @AfterEach
    public void teardown() {
        log.info("[Shark] teardown-springboot");
        list.clear();
    }

    @Test
    public void middle() {
        log.info("[Shark] middle-springboot");
    }

}

Leave a Reply