0

I'm working in a project which contains tests in mockito. I need to add more tests to this file, so I added a simple jqwik test, but if I try to run all tests all mockito ones are ignored.

Laurel
  • 5,965
  • 14
  • 31
  • 57
  • It’s definitely possible. You’ll have to show the details of what you’re doing since there are different ways to bring Mockito into your tests. – johanneslink Jun 17 '22 at 04:20
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 18 '22 at 12:26

1 Answers1

0

"How can I use jqwik with Mockito?" is a common question. Here's a discussion of possible solutions. The most simple one:

class HelloTest {
    @Mock private Logger logger;
    @InjectMocks private MySubjectUnderTest sut;

    private AutoCloseable mockitoCloseable;

    @BeforeProperty //@BeforeTry
    void initMocks() {
        mockitoCloseable = MockitoAnnotations.openMocks(this);
    }

    @AfterProperty //@AfterTry
    void closeMocks() throws Exception {
        mockitoCloseable.close();
    }

    @Property
    void testWithRandomData(@ForAll final String data) {
        sut.doSomething();
        // Verify whatever should happen to logger instance
        // during doSomething() call, e.g.:
        Mockito.verify(logger).log(Level.WARNING, "my message");
    }
}

You go with @Before/AfterProperty or with @Before/AfterTry depending on whether your mocks should be reset for each try or for each property.

johanneslink
  • 4,877
  • 1
  • 20
  • 37