Java 我应该以什么方式测试更新方法?

Java 我应该以什么方式测试更新方法?,java,testing,junit,spring-test,Java,Testing,Junit,Spring Test,我想测试我的更新方法是否将更改保存到作为路径变量传递的对象中,但我堆栈(pet.species中的值没有更改为“gorilla”): 方法之前的此处: @Before public void setUp () throws Exception { mockMvc = MockMvcBuilders.standaloneSetup(new PetController(clinicService)).build(); one = new PetBuilder()

我想测试我的更新方法是否将更改保存到作为路径变量传递的对象中,但我堆栈(pet.species中的值没有更改为“gorilla”):

方法之前的此处:

@Before
public void setUp () throws Exception {

    mockMvc = MockMvcBuilders.standaloneSetup(new PetController(clinicService)).build();

    one = new PetBuilder()
            .id(1L)
            .dateOfBirth("2000-10-12")
            .name("Kajtek")
            .species("dog")
            .weight(2000)
            .build();
这看起来像是我测试的控制器方法(只是让它变得简单,类用requestMapping/pet注释):


我想,当我使用param方法时,我会设置参数名称和值,然后将它们传递到保留在模型中的对象中,但我错了吗?

为什么会错?问题是什么?问题是,这个值没有改变:应该是“gorilla”,但“dog”是“one.getSpecies()”吗?在进行更改后,您是否对其进行了查询?其中一个是我在@Before method中创建的object Pet.class。您可以向我们展示com
@Before
方法和完整的测试方法吗?为什么您会错?问题是什么?问题是,这个值没有改变:应该是“gorilla”,但“dog”是“one.getSpecies()”吗?在进行更改后,您是否对其进行了查询?一个是我在@Before method中创建的object Pet.class。您能否向我们展示com
@Before
方法和完整的测试方法?
@Before
public void setUp () throws Exception {

    mockMvc = MockMvcBuilders.standaloneSetup(new PetController(clinicService)).build();

    one = new PetBuilder()
            .id(1L)
            .dateOfBirth("2000-10-12")
            .name("Kajtek")
            .species("dog")
            .weight(2000)
            .build();
@RequestMapping(value = "update/{id}", method = RequestMethod.POST)
public String update (@Valid @ModelAttribute ("petToUpdate") Pet pet,
                      BindingResult result ) {
    if(result.hasErrors())
        return "pet/update/{id}";

    clinicService.saveAndFlush(pet);

    return "redirect:/pet/findById/{id}";

}