2. 因爲spring-test-dbunit 的註解配置,致使 mockito 中的 @MockBean 失效,須要將 MockitoTestExecutionListener 和 DbUnitTestExecutionListener 配置到 @TestExecutionListeners 中
web
@ActiveProfiles(value = "test") @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionDbUnitTestExecutionListener.class, MockitoTestExecutionListener.class, DbUnitTestExecutionListener.class}) @AutoConfigureMockMvc public abstract class ApplicationTests { @Test public void contextLoads() { } }