Using the most basic example from Mockito's examples page, I am able to run successfully in JUnit.
However, when I run the same test in Spock, it 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 is the error I get when the 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)
at SimpleSpockTest.Basic Mock Test(SimpleSpockTest.groovy:25)
Any ideas or suggestions? I really like Spock and Mockito and am hoping to get them working well together. Thank you very much!