Junit下获取src/test/resource路径
package com.lmx.controller;
import org.junit.Test;
public class AdminControllerTest {
@Test
public void test() {
String rootPath=this.getClass().getResource("/a.txt").getFile().toString();
System.out.println(rootPath);
String rootPath1 = this.getClass().getResource("/a.txt").toString();
System.out.println(rootPath1);
String rootPath2 = this.getClass().getResource("/").toString();
System.out.println(rootPath2);
String rootPath3 = this.getClass().getResource("").toString();
System.out.println(rootPath3);
}
}
输出结果:
/E:/STSTest/ptest/target/test-classes/a.txt
f