Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot @MockBean不能流利地使用testNG_Spring Boot_Testng_Spring Test - Fatal编程技术网

Spring boot @MockBean不能流利地使用testNG

Spring boot @MockBean不能流利地使用testNG,spring-boot,testng,spring-test,Spring Boot,Testng,Spring Test,有了JUnit,我可以轻松地使用@MockBean: @SpringBootTest(classes = AppConfig.class) @RunWith(SpringRunner.class) public @Log class ServiceDrhImplTest_JUnit { private @Autowired ServiceDrh serviceDrh; private @MockBean EmployeDao employ

有了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语法,mock是空的。 我必须将@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已经知道您的问题,但尚未修复:

即使Spring Boot的文档没有引用TestNG,它也为TestNG提供了一个测试示例: