Easy to get a test file into JUnit

Posted by Benju on Stack Overflow See other posts from Stack Overflow or by Benju
Published on 2010-04-08T02:49:52Z Indexed on 2010/04/08 2:53 UTC
Read the original article Hit count: 349

Filed under:
|

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 this case) in as a giant String or read it in as a file but is there a shortcut specific to Junit like this?

public class MyTestClass{

@Resource(path="something.xml")
File myTestFile;

@Test
public void toSomeTest(){
...
}

}

© Stack Overflow or respective owner

Related posts about junit

Related posts about junit4