通过Jenkins MVN构建执行Junit测试用例时找不到Hibernate.cfg.xml文件

时间:2017-09-15 22:30:29

标签: hibernate junit

我有一个Springboot&基于Hibernate的项目在我的本地(STS)和Jenkin中运行良好,Jenkin是从源代码库运行的。 现在我已经开发了一些Junit测试用例,它在我的本地(STS)运行得非常好。但是在运行Jenkin时,Build失败了。它将ERROR作为" hibernate.cfg.xml"找不到文件,因此所有测试用例都失败了。我相信这只是因为Junit测试用例无法找到这个cfg文件。我的所有测试用例都在" src / test / java"的标准位置。 我的代码如下:configuration.configure(new File(hbmFilePath));

要解决此问题,我已经放置了" hibernate.cfg.xml"在所有可能的位置,以便找到它,如: - >

1)src/main/resource/hibernate.cfg.xml
2)src/test/resources/hibernate.cfg.xml
3)hibernate.cfg.xml (i.e. at root of source package as well)

但仍然无法找到" hibernate.cfg.xml"。

1 个答案:

答案 0 :(得分:0)

我从:

更改了hbm文件路径
  

configuration.configure(new File(hbmFilePath));

进入 -

  

configuration.configure(hbmFilePath);

...并且所有Junits测试用例都已成功运行。意思是说这种方法能够从测试用例中找到hbm文件。