测试用例所在工程目录为:D:/workspace/EasyMockDemo,要获得当前类所在路径:
package org.leechau.groovyEmbedded;
import org.junit.Test;
public class HelloWorld {
@Test
public void HelloTest() throws Exception {
String path = this.getClass(). getResource("") .getPath();
System.out.println(path);
}
}
输出:/D:/workspace/EasyMockDemo/bin/org/leechau/groovyEmbedded/
如果将 getResource("")改为getResource("/"),则输出为:/D:/workspace/EasyMockDemo/bin/
如果希望获得项目目录,则用System.out.println(System.getProperty("user.dir"));
输出为:D:\workspace\EasyMockDemo
.