看到 org.mockito.exceptions.misusing.NotAMockException 的问题

问题描述

看到一个关于 spy 和 auto-wire 以及 Extend(SpringExtention) 的问题

Argument 应该是一个模拟,但是是:class org.springframework.data.jpa.repository.support.SimpleJpaRepository

    @ExtendWith(SpringExtention.class)
    @SpringBoottest(classes = TestServer.class)
    @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
    @ActiveProfiles("test")
    @Transactional
    SampleServiceTest {
    
    @Spy
    @Autowire
    private TestRepo repo;
    @Mock
    SpecialTest test;
    @Mock
    SpecialTest1 test1;
    @InjectMock
    TestServiceTest testService;
    
    @InjectMock
    SampleServiceTest sampleServiceTest;

    @BeforeEach()
    void setup () {
       openMocks(this);
    when(testService.getId()).thenReturn(test);
    when(testService.getId()).thenReturn(test1);
    }

   @Test
   void test () {

   }

当我使用 spring-boot: 2.4.1 时,我看到了上述问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)