joaomlneto/travis-ci-tutorial-java

Resources

svaningelgem opened this issue · 1 comments

Hello,

Could you be so kind as to write on how to test with resources (for example opening a file from the test-resources directory)?

Thanks

That's a bit out of the scope of this repo, but see this answer on StackOverflow.

You can access /src/test/resources/file.txt in the following way:

	@Test
	public void testOpenResources() throws IOException {
		Path path = Path.of(getClass().getResource("/file.txt").getPath());
		String content = Files.readString(path, StandardCharsets.US_ASCII);
		assertEquals("Hello world\n", content);
	}