我发现"旧样式",如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
答案 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
}
}