Easy way to get a test file into JUnit

前端 未结 5 1823
面向向阳花
面向向阳花 2020-12-08 04:04

Can somebody suggest an easy way to get a reference to a file as a String/InputStream/File/etc type object in a junit test class? Obviously I could paste the file (xml in t

5条回答
  •  鱼传尺愫
    2020-12-08 04:11

    If you need to actually get a File object, you could do the following:

    URL url = this.getClass().getResource("/test.wsdl");
    File testWsdl = new File(url.getFile());
    

    Which has the benefit of working cross platform, as described in this blog post.

提交回复
热议问题