2016-04-25 35 views
6

運行DataJpaTest我寫了一個測試JPA與Spring引導如下解釋: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4PostgreSQL的

@RunWith(SpringRunner.class) 
@DataJpaTest 
public class UserRepositoryTests { 

@Autowired 
private TestEntityManager entityManager; 

... 
} 

這將配置一個內存數據庫默認。我怎樣才能配置這個測試,它使用我的本地PostgreSQL數據庫?

+1

您是否嘗試過用你的application.properties定義DB? –

+0

是的,我在application.properties中配置了PostgrSQL並添加了相應的Postgres依賴項。 –

回答

12

如果要使用相同的數據源作爲普通的應用程序,你可以使用:

@RunWith(SpringRunner.class) 
@DataJpaTest 
@AutoConfigureTestDatabase(replace=Replace.NONE)