Unit testing Feign clients

Let's create a unit test class; this test class can have several test methods but in this example, we have created three @Test methods, to test our client. The test will use static imports from the org.hamcrest.CoreMatchers.* and org.junit.Assert.* packages:

@Test 
public void findAllAccountTest() throws Exception { 
   List<Account> accounts = accountService.findAll(); 
   assertTrue(accounts.size() > 4); 
} 
  
@Test 
public void findOneAccountTest() throws Exception { 
    Account account = accountService.findByAccountId(1001); 
    assertThat(account.getCustmer().getCustomerName(), 
containsString("Arnav")); } @Test public void createAccountTest() throws Exception { Account account = new Account(1001, 2304.32, 100, 'SAVING',
'HDFC0011', 'HDFC') accountService.create(account); account = accountService.findByAccountId(1001); assertThat(account.getBank(), containsString("HDFC")); }

We have written unit test cases to test the accountService Feign client. In the first test method, we fetched all accounts in a list—the size of the list must be greater than five. In the second test method, we fetched one account with the 1001 account ID—the associated customer name must be Arnav. In the third test method, we created an account using the accountService Feign client.

..................Content has been hidden....................

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