JUNIT not identifying resources under src/test folder
you can use classLoader like this :
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("somefile").getFile());
Why Can't I access src/test/resources in Junit test run with Maven?
MainConfig.xml directly. The
src/test/resources directory contents are placed in the root of your CLASSPATH.
More precisely: contents of
src/test/resources are copied into
target/test-classes, so if you have the following project structure:
│ └── foo
│ └── C.java
It will result with the following test CLASSPATH contents:
To actually access the files from Java source, use
Java path to file in src/main/resources
The problem was that I have not included the resource in the maven build in pom file. When I included the following it worked with
Unable to access test resources from junit tests
Alright so Timo was able to figure it out. I hadn't rebuilt the project for a while (:facepalm:). Coming from the python world here, where things are a little different. Thanks for working through this with me everyone, it really means a lot!
file not found on path src/test/resources/
You should never depend on
InputStream from classpath.
Both src/main/resources and src/test/resources are in the classpath if you use the Maven standard directory structure.
I tend to like the Apache Commons IO library and Spring
Calculating the Angle Between Two Lines Without Having to Calculate the Slope (Java)
How to Make a Java Program Quit When "Q" Is Inputted, Issue Is the Default Input Variable Is Double
Regular Expression to Match a Backslash Followed by a Quote
How to Get the Parent Element Name of a Child Element in Json
Changing Scene When a Button Is Pressed Fxml
Custom Pagination by Array List
How to Mark Cucumber Junit Step as Failed But Continue
How to Change Background Colour to Specific Viewholder Items in a Recycleview
Beanutils Copyproperties API to Ignore Null and Specific Propertie
Converting Date to 08:00:00.000+0000
Spring Boot API Call With Multiple @Requestparam
Multiple Queries Executed in Java in Single Statement
Enable Jackson Deserialization of Empty Objects to Null
How to Find the Number of Times If or Else Code Has Executed
Round Off a Double While Maintaining the Trailing Zero
How to Post Data in an Array in Android Using Retrofit 2