Announcement Announcement Module
No announcement yet.
spring data crudrepo and junit test issue Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring data crudrepo and junit test issue

    I have a Junit test class that contains two methods-- one that saves into the database using an interface that extends CrudRepo and the other method that retrieves data from the database. When I run my tests, the save works but the retrieve doesn't. Any ideas why? See below Test class. The "MyTestRepo" extends CrudRepository so it includes the default findOne():

    private MyTestRepo repo;
    public void saveIntoTestRepo(){
        SomeObject so = new SomeObject();
        SomeObject result =;
        assertThat(result.getId(), is(notNullValue()));  //this passes, the id = 1
    public void retrieveSO() {
        repo.count();  // this is correct, returns 1
        SomeObject result = repo.findOne(1L);  //this should return the hydrated SomeObject instance with id = 1
        assertThat(result, is(notNullValue()));  // Fails here since the result is null...