I have a java, gradle project. My Junit
src/test/java/hello/TestHelloWorld.java
picks some configurations from
src/test/resources/testdata0010.csv
the code in Junit to pick this file is
URL url = this.getClass().getResource("/testdata0010.csv");
File testWsdl = new File(url.getFile());
When I run
gradle test
this works alright. The Junit is able to pick data from the csv file.
When I run the Junit in Eclipse, ie by Shift+Alt+XT, then the Junit breaks with a null pointer exception.
I understand the reason. When I run Junit inside eclipse, it looks for the file in the same folder, does not find it and fails. However, when I run the test using gradle, the csv file is already available in classpath and hence the Junit finds it.
I am looking for some way to have Junit work from within Eclipse.
Ended up being quite simple really. If you include any folder into the buildpath in Eclipse (by rightclicking on the folder and then choose buildpath from the menu) you can solve the problem. Now when I run Junit from within Eclipse, it find the csv file in the buildpath and works well. Care needs to be taken to have this work with gradle or maven, whatever your choice of builder is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.