I know you said you didn't want to read the file in by hand, but this is pretty easy
public class FooTest
{
private BufferedReader in = null;
@Before
public void setup()
throws IOException
{
in = new BufferedReader(
new InputStreamReader(getClass().getResourceAsStream("/data.txt")));
}
@After
public void teardown()
throws IOException
{
if (in != null)
{
in.close();
}
in = null;
}
@Test
public void testFoo()
throws IOException
{
String line = in.readLine();
assertThat(line, notNullValue());
}
}
All you have to do is ensure the file in question is in the classpath. If you're using Maven, just put the file in src/test/resources and Maven will include it in the classpath when running your tests. If you need to do this sort of thing a lot, you could put the code that opens the file in a superclass and have your tests inherit from that.