Test coverage 0% using Spring-boot-starter-test


(Fotis Tsakiroglou) #1

I am new in SonarQube.I am trying to set my first test report.
The problem is that although I have some test running successfully, I get 0 lines coverage in my Sonar report.

For example, I have a simple unittest:

@RunWith(SpringRunner.class)
@WebMvcTest(FriendController.class) 
public StandaloneControllerTests
{
@MockBean
FriendService friendService;

@Autowired
MockMvc mockMvc;

and a function using Mockito

@Test
public void testCreateReadDelete() throws Exception
{
Friend("Michael","Jordan");
Arrays.asList(friend);

Mockito.when(friendService.findAll()).thenReturn(friends);
mockMvc.perform(get("/friend"))
.andExpect(status().isOk())

Matchers.hasSize(1)))
.andExpect(jsonPath("$[0].first-name", Matchers.is("Michael")));
}

I post to sonar runing:

mvn sonar:sonar -Dsonar.projectKey=my_example -Dsonar.organization=myaccount-github -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=mylogin

Any ideas?
Thank you.


(Evgeny Mandrikov) #2

(Fotis Tsakiroglou) #3

I see.
Thank you very much.
Indeed I had to add Jacoco plugin into my project.
Then running mvn test, created a report and uploaded in SonarQube account.