Quantcast

[sonar-dev] mockito verify - Tests should include assertions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[sonar-dev] mockito verify - Tests should include assertions

Andrew Holland
Hi,

is it possible that the “Tests should include assertions” rule can support Mockito verify() calls?

Thanks

Andrew
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] mockito verify - Tests should include assertions

Nicolas Peru
Hi Andrew, 

This is totally something we can envisage, can you provide a little bit more detailed example ?  And if you can think about it some edge cases we should or should not detect ?
(and moreover, the case where you expect to get/not get an issue).

Thanks.

Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com


2015-05-19 20:49 GMT+02:00 Andrew Holland <[hidden email]>:
Hi,

is it possible that the “Tests should include assertions” rule can support Mockito verify() calls?

Thanks

Andrew
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] mockito verify - Tests should include assertions

Andrew Holland
Hi Nicolas,

Here’s the example from mockito’s website. (http://site.mockito.org/mockito/docs/current/org/mockito/Mockito.html)
   
//Let's import Mockito statically so that the code looks clearer
02import static org.mockito.Mockito.*;
03 
04//mock creation
05List mockedList = mock(List.class);
06 
07//using mock object
08mockedList.add("one");
09mockedList.clear();
10 
11//verification
12verify(mockedList).add("one");
13verify(mockedList).clear();


i would expect verify(...), verifyNoMoreInteractions(...), verifyZeroInteractions(..) calls to each count as an assert.

maybe you could implement it in a more generic way in that an junit/fest assert is within a method called from the test.

Thanks

Andrew


On 19 May 2015, at 19:58, Nicolas Peru <[hidden email]> wrote:

Hi Andrew, 

This is totally something we can envisage, can you provide a little bit more detailed example ?  And if you can think about it some edge cases we should or should not detect ?
(and moreover, the case where you expect to get/not get an issue).

Thanks.

Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com


2015-05-19 20:49 GMT+02:00 Andrew Holland <[hidden email]>:
Hi,

is it possible that the “Tests should include assertions” rule can support Mockito verify() calls?

Thanks

Andrew
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] mockito verify - Tests should include assertions

Jean-Baptiste Lièvremont
I would also raise an issue when a call to verify(...) is not followed by a method call:

  List mockedList = mock(List.class);

  // Non compliant
  verify(mockedList);

  // Compliant
  verify(mockedList).clear();

Does it make sense?


Jean-Baptiste LIEVREMONT | SonarSource
Platform Developer

2015-05-19 21:40 GMT+02:00 Andrew Holland <[hidden email]>:
Hi Nicolas,

Here’s the example from mockito’s website. (http://site.mockito.org/mockito/docs/current/org/mockito/Mockito.html)
   
//Let's import Mockito statically so that the code looks clearer
02import static org.mockito.Mockito.*;
03 
04//mock creation
05List mockedList = mock(List.class);
06 
07//using mock object
08mockedList.add("one");
09mockedList.clear();
10 
11//verification
12verify(mockedList).add("one");
13verify(mockedList).clear();


i would expect verify(...), verifyNoMoreInteractions(...), verifyZeroInteractions(..) calls to each count as an assert.

maybe you could implement it in a more generic way in that an junit/fest assert is within a method called from the test.

Thanks

Andrew


On 19 May 2015, at 19:58, Nicolas Peru <[hidden email]> wrote:

Hi Andrew, 

This is totally something we can envisage, can you provide a little bit more detailed example ?  And if you can think about it some edge cases we should or should not detect ?
(and moreover, the case where you expect to get/not get an issue).

Thanks.

Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com


2015-05-19 20:49 GMT+02:00 Andrew Holland <[hidden email]>:
Hi,

is it possible that the “Tests should include assertions” rule can support Mockito verify() calls?

Thanks

Andrew
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] mockito verify - Tests should include assertions

Andrew Holland
yes, looks good.

On 20 May 2015 at 08:34, Jean-Baptiste Lièvremont <[hidden email]> wrote:
I would also raise an issue when a call to verify(...) is not followed by a method call:

  List mockedList = mock(List.class);

  // Non compliant
  verify(mockedList);

  // Compliant
  verify(mockedList).clear();

Does it make sense?


Jean-Baptiste LIEVREMONT | SonarSource
Platform Developer

2015-05-19 21:40 GMT+02:00 Andrew Holland <[hidden email]>:
Hi Nicolas,

Here’s the example from mockito’s website. (http://site.mockito.org/mockito/docs/current/org/mockito/Mockito.html)
   
//Let's import Mockito statically so that the code looks clearer
02import static org.mockito.Mockito.*;
03 
04//mock creation
05List mockedList = mock(List.class);
06 
07//using mock object
08mockedList.add("one");
09mockedList.clear();
10 
11//verification
12verify(mockedList).add("one");
13verify(mockedList).clear();


i would expect verify(...), verifyNoMoreInteractions(...), verifyZeroInteractions(..) calls to each count as an assert.

maybe you could implement it in a more generic way in that an junit/fest assert is within a method called from the test.

Thanks

Andrew


On 19 May 2015, at 19:58, Nicolas Peru <[hidden email]> wrote:

Hi Andrew, 

This is totally something we can envisage, can you provide a little bit more detailed example ?  And if you can think about it some edge cases we should or should not detect ?
(and moreover, the case where you expect to get/not get an issue).

Thanks.

Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com


2015-05-19 20:49 GMT+02:00 Andrew Holland <[hidden email]>:
Hi,

is it possible that the “Tests should include assertions” rule can support Mockito verify() calls?

Thanks

Andrew
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email






Loading...