【问题标题】:@MockBean not fluent with testNG@MockBean 不熟悉 testNG
【发布时间】:2017-08-03 14:28:48
【问题描述】:

有了 JUnit,我可以轻松使用 @MockBean:

    @SpringBootTest(classes = AppConfig.class)
    @RunWith(SpringRunner.class)
    public @Log class ServiceDrhImplTest_JUnit {

        private @Autowired ServiceDrh serviceDrh;
        private @MockBean EmployeDao employeDao;
        private @MockBean SalaireDao salaireDao;

但是使用 TestNG 它不能开箱即用,使用 abov 语法,模拟为空。 我必须将@Autowired 添加到@MockBean 才能使其正常工作。 每次测试后都不会重置更多的模拟,我必须这样做:

    @SpringBootTest(classes = AppConfig.class)
    public @Log class ServiceDrhImplTest_TestNG extends AbstractTestNGSpringContextTests {

        private @Autowired ServiceDrh serviceDrh;
        private @MockBean @Autowired EmployeDao employeDao;
        private @MockBean @Autowired SalaireDao salaireDao;

        @AfterMethod
        public void afterMethod() {
            Mockito.reset(employeDao, salaireDao);
        }

你确认这种行为吗? 这是否意味着 Spring 停止支持 TestNG,因为它不再出现在 spring-boot ref doc 中?

【问题讨论】:

    标签: spring-boot testng spring-test


    【解决方案1】:

    Spring 已经知道您的问题,但尚未修复:https://github.com/spring-projects/spring-boot/issues/7689

    而且即使Spring Boot的文档没有引用TestNG,也提供了TestNG的测试样例:https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-testng

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多