简体   繁体   中英

Path to XML dataset in DBUnit

I am using DBUnit for my integration tests and I was able to create a XML dataset. I added the dataset.xml file in the resources folder (standard Maven project). However when I try to just say new File("dataset.xml"); it doesn't find the file and it prints that it tried to combine what I wrote with the path of my glassfish domain folder. I tried with an absoulute path and it works...but that can't be the right way of doing it?

FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
IDataSet dataSet = builder.build(new File("/home/dude/Projects/Java/SecretProject/Code/Backend/SuperApp/src/test/resources/dataset.xml"));

I had the same problem in my IntelliJ project...

I was using file import via annotation

@DatabaseSetup("UserServiceTest.xml")

and placing identical to java package tree in resources solved my problem ie:

src
  -main
    -test
      -java
        -com/site/service
          -userServiceTest
      -resources 
        -com/site/service
          -UserServiceTest.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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