• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

coverage testing jacoco and mokito

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,I have a question with the coverage tests and the use of Mokito object

In my test class

@Test
public String savePessoaWithErro(){
when(result.hasErrors()).thenReturn(true);
String returnSavePessoa= appController.savePessoa(any(Pessoa.class), result, model);
/* when appController.savePessoa(any(Pessoa.class), result, model) , and result.hasErrors()=true, appController return pessoaadd */
AssertJUnit.assertEquals(returnSavePessoa,"pessoaadd");
return anyString();


}

In my controller class
@RequestMapping(value = { "/newpessoa" }, method = RequestMethod.POST)
public String savePessoa(@Valid Pessoa pessoa, BindingResult result, ModelMap model) {

if (result.hasErrors()) {
return PESSOAADD;
}



model.addAttribute(SUCCESS, pessoaService.save(pessoa));

return "pessoaRegistrationsuccess";
}


But jacoco,mark this as not covered and do not understand the reason.
someone would know the reason?
I appreciate your help and time
Thank you
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you've used a mock object of the controller you're trying to test rather than the real one.

This means two things: you're not getting coverage, and most importantly you're not getting coverage because you're not actually testing the controller.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic