I'm taking over a project and have to assume that the tests worked at some point the way I find them (boiled down to what should not be null):
@Test
public void testCoding() {
assertNotNull(getClass().getResourceAsStream("/myfile.json"));
//assertNotNull(MyTest.class.getResourceAsStream("/myfile.json"));
//assertNotNull(MyTest.class.getClassLoader().getResourceAsStream("myfile.json"));
//...
}
with myfile.json
in src/test/resources/
and the test in src/test/java/some/package/
.
I tried putting myfile.json
into the same folder as the test, in the src/java folder, I tried with and without leading /
and with /resources
and all the tips I found on SO.
The gradle file is:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile "junit:junit:$junitVersion"
}
What am I missing?
Update:
I realized that the source code is in the open source part of our project and that it does fail in AS, only.
Here is the line that fails if I right-click the lt-api/src/test/java/
folder and select "Run All Tests". The Gradle console prints out this line:
Executing tasks: [:lt-api:compileJava, :lt-api:testClasses, :mbwlib:compileJava, :mbwlib:testClasses, :bitlib:compileJava, :bitlib:testClasses]
Running ./gradlew clean :lt-api:compileJava :lt-api:testClasses :mbwlib:compileJava :mbwlib:testClasses :bitlib:compileJava :bitlib:testClasses
does not trigger the error but neither does it run tests. (How can I know what exactly AS is doing there? I thought AS was doing gradle all the way now?)
Running
./gradlew clean :lt-api:test
I get the tests to run (adding a typo results in failing tests) but it doesn't trigger the issue I originally had and that I'd like to understand.
Where should the file be?
$ sudo updatedb
$ locate test-classes
$ locate ungargasse.json
/path/to/project/lt-api/build/resources/test/ungargasse.json
/path/to/project/lt-api/src/test/resources/ungargasse.json