Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test resources not available to unit tests #33

Open
SingingBush opened this issue Apr 7, 2018 · 2 comments
Open

test resources not available to unit tests #33

SingingBush opened this issue Apr 7, 2018 · 2 comments

Comments

@SingingBush
Copy link

I've got exports my.package to junit; in my module-info and most of my tests can now run while building but some tests rely on test data that I place in src/test/resources. when doing a build these tests fail as the resources are not found. I've tried various ways to get the resources such as:

InputStream stream = getClass().getModule().getResourceAsStream("testdata.txt");
InputStream stream = getClass().getClassLoader().getResourceAsStream("testdata.txt");
@SingingBush
Copy link
Author

for now I have a workaround that works when running the tests in Intellij as well as when the tests are run during the gradle build:

    private Reader loadTestResource(final String resource) throws IOException {
        final InputStream stream = ClassLoader.getSystemResourceAsStream(resource);

        return stream != null ?
                new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8"))) :
                Files.newBufferedReader(Paths.get("src/test/resources/" + resource));
    }

@udaychandra
Copy link

Yes, the test resources aren't being picked up by the modular setup. I tried modifying the test source set output directory for resources and it seems to be working:

sourceSets {
    test {
        output.resourcesDir = "build/classes/java/test"
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants