title: Autowired TestEntityManager Has Null Pointer on TestEntityManager Object
body: <p>I want to test a Spring Boot application using Spring Data REST and Spring Data JPA.  However the TestEntityManager object in the test file doesn't get autowired and thus is null.  I googled online and didn't find out what I have done wrong in the unit test file.  Can someone please help?</p>
  
  <p>Entity -- Student:</p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "STUDENT")
  public class Student {
  
      @Column(name = "STUDENT_ID")
      private Integer id; 
  
      .....// other fields
     }
  </code></pre>
  
  <p>And the Student repository:</p>
  
  <pre><code>public interface StudentRepository extends CrudRepository&lt;Student , Integer&gt;{
    Student findById(@Param("id") int id);
  }
  </code></pre>
  
  <p>And I have a SpringApplication main file, but no controller.</p>
  
  <p>And here is my test file.  I also tried with @SpringBootTest and @AutoConfigureTestEntityManager, but the entityManager is still null.</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @DataJpaTest
  public class StudentRepositoryTest {
  
      @Autowired
      private static TestEntityManager entityManager;  // entityManager is always Null 
  
      @Autowired
      private static StudentRepository repository; 
  
      private static Student student;
  
      @BeforeClass
      public static void setUp() throws Exception {
  
          entityManager.persistAndFlush(new Student("1"));  
            // Null Pointer exception because entityManager is null.
      }
  
      @Test
      public void testFindById() {        
          assertNotNull(repository.findById());       
     }
  }
  </code></pre>