java - Simple Mockito verify works in JUnit but not Spock -


using basic example mockito's examples page, able run in junit.

however, when run same test in spock, fails.

junit/java version (this passes):

import org.junit.test;  import java.util.list;  import static org.mockito.mockito.mock; import static org.mockito.mockito.verify;  public class simplejunittest {     @test     public void basicmocktest()     {         list mockedlist = mock(list.class);          //using mock object         mockedlist.add("one");         mockedlist.clear();          //verification         verify(mockedlist).add("one");         verify(mockedlist).clear();     } } 

spock/groovy version (this fails):

import static org.mockito.mockito.mock import static org.mockito.mockito.verify   class simplespocktest extends spock.lang.specification {     def "basic mock test"()     {         given:             //mock creation             list mockedlist = mock(list.class);          when:             //using mock object             mockedlist.add("one");             mockedlist.clear();          then:             //verification             verify(mockedlist).add("one");             verify(mockedlist).clear();     }  } 

here error when spock test fails:

condition not satisfied:  verify(mockedlist).add("one") |      |           | |      |           false |      $java.util.list$$enhancerbymockitowithcglib$$172e393a@613043d2 (renderer threw     nullpointerexception) $java.util.list$$enhancerbymockitowithcglib$$172e393a@613043d2 (renderer threw  nullpointerexception)  @ simplespocktest.basic mock test(simplespocktest.groovy:25) 

any ideas or suggestions? spock , mockito , hoping them working together. thank much!

roughly speaking, then-block may contain assertions in form of boolean expressions. mockito verification expression doesn't fit contract, return falsy value (null, false, 0) when passes, interpreted failed assertion spock.

to solve problem, can either write helper method wraps around verification expressions , returns true, or can use spock's built-in mocking framework instead of mockito.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -