Я пытаюсь запустить тестовый пример ниже в Spring Boot.
:: Spring Boot :: (v2.3.1.RELEASE)
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = com.dineoutsafe.api.dosadmin.DOSAdminAPIApplication.class)
@ActiveProfiles("test")
public class POSTSessionTest {
public POSTSessionTest() {
System.out.println("Calling post construct");
}
@Test
public void testOne(){
assertThat(45,equalTo(30+15));
}
@Test
public void testTwo(){
assertThat(45,equalTo(30+15));
}
@Test
public void testThree(){
assertThat(45,equalTo(30+15));
}
@Test
public void testFour(){
assertThat(45,equalTo(30+15));
}
@Test
public void testFive(){
assertThat(45,equalTo(30+15));
}
}
И Я заметил, что конструктор запускается несколько раз. На самом деле он запускается (количество @Test -1) раз. В стандартном выводе
2020-06-21 16:00:26.668 INFO 93912 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-06-21 16:00:26.679 INFO 93912 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-06-21 16:00:27.025 INFO 93912 --- [ Test worker] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-06-21 16:00:27.034 INFO 93912 --- [ Test worker] c.d.a.d.i.session.POSTSessionTest : Started POSTSessionTest in 5.511 seconds (JVM running for 6.414)
Calling post construct
Calling post construct
Calling post construct
Calling post construct
Такое же поведение я заметил для @PostConstruct. Это нормально для @SpringBootTest?