我知道如果我們使用 annotation @SpringBootTest,我們就會連接整個應用程式。
但是如果我只需要運行這個類而不啟動整個應用程式,我該如何替換@SpringBootTest?
uj5u.com熱心網友回復:
我用 @ContextConfiguration(classes = ClassThatYouAreGoingToTest.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = ClassThatYouAreGoingToTest.class)
public class TestClass{
@MockBean
private BeanUsedInYourTestClass beanUsedInYourTestSubject;
.....///another mock bean if required
@Autowired
private ClassThayYouAreGoingToTest testSubject;
///your @Tests
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/403428.html
標籤:
