简体   繁体   English

适用于非Spring应用程序的Junit测试嵌入式数据库

[英]Embedded Database for Junit Tests for non-spring application

I am looking for a embedded database which I can use in JUnit 4.12 tests. 我正在寻找可以在JUnit 4.12测试中使用的嵌入式数据库。 Because of the current nature of our code base & time-lines it is not possible for us to mock the database calls. 由于我们的代码库和时间表的当前性质,因此我们无法模拟数据库调用。 We are concerned only about Mysql database. 我们只关心Mysql数据库。 So I am looking for some kind of Embedded database which I can initialize before our each test run & then clear it after the tests. 因此,我正在寻找某种嵌入式数据库,可以在每次测试运行之前对其进行初始化,然后在测试之后将其清除。 Some what similar to what wiremock does for http server. 一些类似于Wiremock对http服务器所做的事情

I have gone through this & it seems it is possible to achieve it via H2 embedded database. 我已经经历了这个 &似乎有可能通过H2嵌入式数据库来实现它。 Most of the links I have found in the web talks about using it with Spring. 我在网络上找到的大多数链接都谈到将其与Spring结合使用。

Can some one let me know 可以让我知道吗

  1. If it is possible to achieve the same using H2 as embedded database for Junit tests for non-spring application? 如果使用H2作为嵌入式数据库进行非Spring应用程序的Junit测试,是否可以实现相同的目标? If yes can someone let me know how to do this or point me to some link where this use case is explained? 如果是,有人可以让我知道如何执行此操作,或者可以将我指向指向解释此用例的某个链接吗?
  2. Also is there some other tools other than H2 which I can use to achieve my goals? 除H2之外,还有其他一些我可以用来实现目标的工具吗?

I think you can use H2, but I prefer to use hsqldb for this purpose. 我认为您可以使用H2,但是我更愿意使用hsqldb来实现此目的。 I need some embedded db which can imitate some oracle-specific features in sql. 我需要一些嵌入式db,它可以模仿sql中某些oracle特定的功能。 From my best knowledge you can use any embedded java database for unit testing. 据我所知,您可以使用任何嵌入式Java数据库进行单元测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM