title: How to write Junit test cases for spring boot application?
body: <p>I have to write some junit test cases to check entity. I'm using postgres as my database.</p>
  
  <p>My entity class</p>
  
  <pre><code>@Entity
  @Table(name = "display")
  public class Display {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  private String title;
  private String group;
  
  public Display() {
  
  }
  public Display(Long id, String title, String grp) {
      this.id = id;
      this.title= title;  
      this.group= grp;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public Long getId() {
      return this.id;
  }
  
  public void setGroup(String id) {
      this.group = id;
  }
  
  public String getGroup() {
      return this.group;
  }
  
  public void settitle(String title) {
      this.title = title;
  }
  
  public String gettitle() {
      return this.title;
  }
  
  }
  </code></pre>
  
  <p>My repository</p>
  
  <pre><code>@Repository
  public interface DisplayRepository extends CrudRepository&lt;Display, Long&gt; {
  
  }
  </code></pre>
  
  <p>Interface</p>
  
  <pre><code>public interface IDisplayService {
      List&lt;Display&gt; findAll();
  }
  </code></pre>
  
  <p>Service class</p>
  
  <pre><code>@Service
  public class DisplayService implements IDisplayService {
      @Autowired
      private DisplayRepository repository;
  
  @Override
  public List&lt;Display&gt; findAll() {
      List&lt;Display&gt; d = (List&lt;Display&gt;) repository.findAll();
      return d;
  }
  }
  </code></pre>
  
  <p>I tried writing junit test cases but I get Could'nt load Application. Whats the right way to write junit test cases for this?</p>
  
  <p>This is the test case I wrote for service</p>
  
  <p>folder : test/java/example/demo/Test.java</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  @TestPropertySource("classpath:conn.properties")
  
  public class DisplayServiceTest {
  
  
  @Value("${id}")
  private String value;
  
  
  @Mock
  private DisplayRepository DisplayReps;
  
  @InjectMocks
  private DisplayService DisplayService;
  
  @Test
  public void whenFindAll_thenReturnProductList() {
  
  Menu m = new Menu()
  m.setId(value);
  
      List&lt;Display&gt; expectedDisplay = Arrays.asList(m);
      doReturn(expectedDisplay).when(DisplayReps).findAll();
      List&lt;Display&gt; actualDisplay = DisplayService.findAll();
      assertThat(actualDisplay).isEqualTo(expectedDisplay);
  }
  </code></pre>
  
  <p>in test/java/example/demo/resources
      conn.properties
      id=2</p>
  
  <p>Its returning 0 for value
  Whats the issue?
  Thanks </p>