spring命令目标类不注入mock

tjvv9vkg  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(229)

我有一个a级结构:

@Service
Class A implements AInterface {

  private final C c;
  String test(String b) {
   }
}

c类结构:

class C {
  // some methods
}

然后我为这个类编写了拦截器:

@Aspect
@Component
class Interceptor {
  @Around(
  value =
      "execution(* AInterface.test(..)) && args(c)")
   public Object intercept(ProceedingJoinPoint joinPoint, String c) {
      // some logic
   }

}

我正在尝试进行集成测试,并希望将模拟类c注入到a中,但这并没有发生。测试类结构:

@SpringBootTest 
 class ATest {
     // Tried @MockBean also
    @Mock
    private C c;
    @Autowired @InjectMock private AInterface a;

    @BeforeTest {
     MockitoAnnotations.initMocks(this);
     // tried using ReflectionUtils to inject mock
    }

   @Test
    void testTest () {

    // when then logic
    }

    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题