Search code examples
gradledbunit

gradle test doesn't work well


When I run test in IntelliJ, it works well, but if I run it by command line like

gradle test or gradle clean test

it rerurns java.io.FileNotFoundException

String FILE_PATH = "sample/src/test/resources/" 
IDataSet insertDataSet = new FlatXmlDataSet(new FileInputStream(FILE_PATH + "com/sample/mst.xml"));

Project structure is:

TestProject

  • sample
    • src
      • main
      • test
        • java
          • com
            • sample
              • test.java
        • resources
          • com
            • sample
              • mst.xml
What is wrong, what should I do?


Solution

  • You should change file loading code to:

    getClass().getClassLoader().getResourceAsStream("mst.xml")