Here you can find the source of getResourceDir(final Class> testClass)
Parameter | Description |
---|---|
testClass | test class |
Parameter | Description |
---|---|
RuntimeException | if retrieving the directory failed |
public static File getResourceDir(final Class<?> testClass) throws RuntimeException
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.URISyntaxException; import java.net.URL; public class Main { /**//from w w w. j a va2 s . c o m * Get test resource directory * * @param testClass test class * @return resource directory * @throws RuntimeException if retrieving the directory failed */ public static File getResourceDir(final Class<?> testClass) throws RuntimeException { final URL dir = ClassLoader.getSystemResource(testClass.getSimpleName()); if (dir == null) { throw new RuntimeException("Failed to find resource for " + testClass.getSimpleName()); } try { return new File(dir.toURI()); } catch (URISyntaxException e) { throw new RuntimeException( "Failed to find resource for " + testClass.getSimpleName() + ":" + e.getMessage(), e); } } }