How to do it...

  1. First, we will create a new MockPublisherRepositoryTests test class in the src/test/java/com/example/bookpub directory at the root of our project with the following content:
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.reset; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) public class MockPublisherRepositoryTests { @MockBean private PublisherRepository repository; @Before public void setupPublisherRepositoryMock() { given(repository.count()).willReturn(5L); } @Test public void publishersExist() { assertThat(repository.count()).isEqualTo(5L); } @After public void resetPublisherRepositoryMock() { reset(repository); } }
  1. Execute the tests by running ./gradlew clean test and the tests should get passed
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.252.23