Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在junit测试用例中传递requestBuilder的动态值所需的输入_Java_Junit_Junit5 - Fatal编程技术网

Java 在junit测试用例中传递requestBuilder的动态值所需的输入

Java 在junit测试用例中传递requestBuilder的动态值所需的输入,java,junit,junit5,Java,Junit,Junit5,正在尝试为REST控制器编写JUnit测试用例。 下面是示例 public class EmployeeController{ @Autowired EmployeeService empService; @GetMapping(path="/emp/{empId}) public GetEmpDetails(@PathVariable("empId") int eid,HttpServletRequest req){ return empService.get

正在尝试为REST控制器编写JUnit测试用例。 下面是示例

public class EmployeeController{
@Autowired
EmployeeService empService;

@GetMapping(path="/emp/{empId})
public GetEmpDetails(@PathVariable("empId") int eid,HttpServletRequest req){
 return empService.getEmployeeDetails(empId);
}
}
EmployeeServiceImpl.java

public class EmployeeServiceImpl extends EmployeeService{
public GetEmpDetails getEmployeeDetails(int empId){

//logic to create request builder

GetEmpBuilderFactory fact =new  GetEmpBuilderFactory();  
GetEmpRequest req =  fact.createInstance(sVer,sv,cid,sysenv).withId(empId).withStartDate().build();
GetEmpResponse resp = ...
return resp;
}

}
下面是上述REST控制器的JUnit5测试用例示例

    @ExtendWith(SpringExtension.class)
    @WebMvcTest(controllers=EmployeeController.class)
    class EmpControllerTest{
    
    @AutoWired
    private MockMvc mockMvc;
    @MockBean
    private EmployeeService empService;
    
    @Test
    void getEmpDetails(){
    
   /*studentService.retrieveCourse(Mockito.anyString(),
                        Mockito.anyString())).thenReturn(mockCourse);

        RequestBuilder requestBuilder = MockMvcRequestBuilders.get(
                "/students/Student1/courses/Course1").accept(
                MediaType.APPLICATION_JSON);

        MvcResult result = mockMvc.perform(requestBuilder).andReturn();

        System.out.println(result.getResponse());
        String expected = "{id:Course1,name:Spring,description:10Steps}";
        JSONAssert.assertEquals(expected, result.getResponse()
                .getContentAsString(), false);*/
    }
    }
我对如何传递EmployeeController的请求生成器感到困惑。在这方面的任何投入都会有所帮助。多谢各位