![](/img/trans.png)
[英]Why is my constructor is undefined even though I have made a constructor in another class?
[英]Why .isNotNull(); assertions fails even though I have a controller class?
我是 Spring 启动和测试的新手。 我目前正在学习 baeldung 的教程( https://spring.io/guides/gs/testing-web/ ),我遇到了这个错误。
事实上,当我使用 isNull() 方法时它通过了。 但我不明白这一点,因为我的 controller class 有映射等等。 为什么会是 null?
这是我的 controller class
或者也许这不是这个测试应该如何进行的? 但是他们在baeldung中显示如下
任何帮助表示赞赏。
最好的,
如果您想使用 spring 上下文运行测试用例,您需要在您的测试 class 中提供@SpringBootTest
注释(即在您的测试 ZA2F2ED4F8EBC2CBB4C21A29DC40AB6DZ 中提供Smoke
而不是@SpringBootConfiguration
)。 除了@SpringBootTest
之外的其他选项如下。
对于junit4:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SpringTestConfiguration.class })
public class YourTestClass {}
对于 junit 5:
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = { SpringTestConfiguration.class })
public class YourTestClass
SpringTestConfiguration
class 包含您需要自动装配的所有 bean。 有关 SpringRunner 与 SpringBootTest 的更多详细信息,请阅读文章
你试过 assertNotNull(studentController) 吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.