2017-10-09 263 views
0

我正在嘗試在Spring Boot測試中使用p6spy。我有一個測試類在Spring Boot測試中未加載Gradle測試依賴項

@RunWith(SpringRunner.class) 
@SpringBootTest 

我gradle.build看起來像這樣

dependencies { 
compile('org.springframework.boot:spring-boot-starter-data-jpa') 
runtime('com.h2database:h2') 

testCompile 'p6spy:p6spy:3.0.0' 
testCompile('org.springframework.boot:spring-boot-starter-test') 
} 

至於應用程序本身(運行正常)註解,我添加了新的數據源到測試應用程序 - 上下文。

spring: 
application: 
    name: persistence 
datasource: 
    url: jdbc:p6spy:h2:mem:persistence;DB_CLOSE_ON_EXIT=FALSE 
    username: sa 
    password: 
    driver-class-name: com.p6spy.engine.spy.P6SpyDriver 
jpa: 
database: H2 

但是當我運行我的測試中,我得到這個錯誤

java.lang.IllegalStateException: Cannot load driver class: com.p6spy.engine.spy.P6SpyDriver

對我來說,這看起來像不加載我的依賴關係。起初,我使用@DataJpaTest註解,但是這個註釋甚至忽略了我的新測試應用程序上下文。

任何幫助表示讚賞。

編輯︰我得到它的工作bei手動添加p6spy依賴於使用IntelliJ的測試。現在我確信我的類路徑是錯誤的,但我不知道如何解決它以使其在Gradle中工作。

+0

請將您的項目與https://github.com/p6spy/p6spy-it-spring-boot比較此示例按預期工作。 –

+0

@simas_ch感謝您的提示。我實際上使用過這個幫手,但它不使用p6spy測試(或者我可能是盲目的) – sorencito

+0

爲什麼不使用testCompile('com.h2database:h2')而不是運行時? – Justas

回答

0

該問題位於我的IntelliJ版本中。我將提交一份錯誤報告。

如果有人應該有這個問題,我在項目設置中手動添加了缺失的依賴項。然後它也可以從IDE中使用。