'Junit5 Contorller Test with SpringbootTest can’t load method getParameterName()

version:spring-boot-starter-test 2.2.12.RELEASE When I run junit5 test,I want test controller。 there is code

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = RuoYiApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public abstract class BaseTest {

    @SpyBean
    TokenService mockTokenService;

    @Autowired
    public MockMvc mockMvc;

    @Autowired
    public TestRestTemplate restTemplate;
public class CommonControllerTest extends BaseTest {
    @SpyBean
    CommonController commonController;
    @Autowired
    private MockMvc mockMvc;

    @Test
    public void testFileDownloadNotExists() throws URISyntaxException {
        
        String fileName = "...";
        URI uri = UriComponentsBuilder
            .fromUriString("/common/download")
            .queryParam("fileName", fileName)
            .build()
            .encode()
            .toUri();
        
        RequestEntity<Void> downloadRequest = RequestEntity
            .get(uri).accept(MediaType.APPLICATION_JSON).build();
        
        ResponseEntity<String> response = restTemplate.getForEntity(downloadRequest.getUrl(), String.class);
        assertThat(response.getBody()).isEqualTo(null);
        assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

When the request send to controller,It can't get method ParameterNames,it alos run inspectClass function read class information,but without ParameterNames and The program enter the breakpoint inspectClass read nothing becase of wrong path(com/**/CommonController$MockitoMock$1821216982.class).

It normal when I run SpringBoot Application,it can enter the breakpoint inspectClass read class inputstream。

How solve this problem?

test

read class info

read class the right read class info read class path error

when I change the mockito version from 3.1.0 to 3.6.28 this com/**/CommonController$MockitoMock$1821216982.class changed to com.ruoyi.web.controller.common.CommonController succss by change mockito version

the old version class name

the new version class name



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source