簡體   English   中英

如何編寫數據庫組件的jUnit測試用例?

[英]How to write jUnit test cases for Database Components?

我是jUnit的新手,有一個任務為具有一些復雜數據庫組件的應用程序編寫jUnit測試用例。 我可以為數據庫組件編寫測試用例,並且這些測試用例在本地maven構建創建中運行良好。 但是在部署框中,從jenkins maven命令創建構建時,我沒有可用的數據庫。 請建議!

jUnit的dbUnit擴展旨在在測試運行之間創建一個已知的可重現狀態。 與CI盒(以及本地)上的內存數據庫(例如HSQL或H2)一起使用時,應該適合您。

干杯,

通常的方法是在內存數據庫環境中編寫CRUD功能的單元測試。 這不完全是真實的東西,但是危險性較小。 看一下

http://www.h2database.com/html/main.html

http://www.oracle.com/technetwork/articles/javase/javadb-10-5-142692.html

您可以基於在真實數據庫上運行的模擬和集成測試,將測試與單元測試分開。 僅在Jenkins中運行單元測試

I am working same kind of project. In our application we use test schema and a reusable class which loads the data from the XML(File is same as test class) and Cache the data and removes the data from the table, so that Unit test get intended data. 
We set different profile and these are set via JVM arguments. And these profile have the database details and any other admin stuff required. In case of Junit to run we use the unit test profile.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM