如果我只需要连接一个 class 而不是整个应用程序,如何替换注解 SpringBootTest
How to replace annotation SpringBootTest if I have to wire up only one class, not the whole application
我知道如果我们使用注解 @SpringBootTest
,我们会连接整个应用程序。
但是如果我只需要运行这个class而不启动整个应用程序,我该如何替换@SpringBootTest
?
我用@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
}
我知道如果我们使用注解 @SpringBootTest
,我们会连接整个应用程序。
但是如果我只需要运行这个class而不启动整个应用程序,我该如何替换@SpringBootTest
?
我用@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
}