Spring MockBean注释原因"没有定义MockitoPostProcessor类型的限定bean"

时间:2017-03-18 04:14:24

标签: spring

我发现"旧样式",如RunWith注释和SpringApplicationConfiguration注释,与"新样式"混合? MockBean注释,看起来像:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(TestApplication.class)
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
public class SomeUnitTest {
    @InjectMocks
    @Autowired
    private IWantTestThisService iWantTestThisService;

    @MockBean
    private DependencyInAboveService dependencyInAboveService;

    @Test
    public void testSomething() {
        // your test
    }
}

案件例外:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.test.mock.mockito.MockitoPostProcessor] is defined

1 个答案:

答案 0 :(得分:-1)

要修复此异常,您应该将代码升级到

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class)
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
public class SomeUnitTest {
    @Autowired
    private IWantTestThisService iWantTestThisService;

    @MockBean
    private DependencyInAboveService dependencyInAboveService;

    @Test
    public void testSomething() {
        // your test
    }
}
相关问题