Skip to content

agustafson-atl/jqwik-mockito-original

Repository files navigation

Provides net.jqwik.api.lifecycle.LifecycleHooks to enable usage of Mockito with jqwik.

  • Creates mocks for any fields with Mockito annotations such as org.mockito.Mock or org.mockito.Spy.
  • Resets all mocks between each try, whether those mocks were created programmatically (eg: via calls to Mockito.mock()}) or via annotations.

Installation

implementation("net.jqwik:jqwik-mockito:${jqwikMockitoVersion}")

Usage

import net.jqwik.api.lifecycle.AddLifecycleHook;
import net.jqwik.api.*;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;

import static org.mockito.Mockito.*;

@AddLifecycleHook(MockitoLifecycleHooks.class)
class OrderServiceTest {
    // Either @Mock or Mockito.mock() can be used.
    @Mock
    private OrderRepository orderRepository;
    private OrderRepository orderRepository2 = Mockito.mock();

    // Either @Spy or Mockito.spy() can be used.
    @Spy
    private ConsoleLoggingServiceImpl loggingService;
    private LoggingService loggingService2 = Mockito.spy(new ConsoleLoggingServiceImpl());

    @InjectMock
    private OrderService orderService;

    @Group
    class BasicExamples {
        @Example
        void testBasicExample() {
            when(orderRepository.getOrder(any())).thenReturn(null);
            // testing code
        }
    }

    @Group
    class SomeProperties {
        @Property
        void testProperty() {
            when(orderRepository.getOrder(any())).thenReturn("orderId");
            // testing code
        }
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages