How to get the path of src/test/resources directory in JUnit?

In JUnit, you can use the getClass().getClassLoader().getResource("").getPath() method to get the path of the src/test/resources directory.

Here is an example of how to use this method to get the path of the src/test/resources directory:

import org.junit.Test;

public class MyTest {

  @Test
  public void test() {
    String path = getClass().getClassLoader().getResource("").getPath();
    System.out.println(path);
  }
}

This will print the path of the src/test/resources directory to the console.

Alternatively, you can use the ClassLoader.getSystemClassLoader().getResource("").getPath() method to get the path of the src/test/resources directory:

import org.junit.Test;

public class MyTest {

  @Test
  public void test() {
    String path = ClassLoader.getSystemClassLoader().getResource("").getPath();
    System.out.println(path);
  }
}

This will also print the path of the src/test/resources directory to the console.

You can then use this path to access files in the src/test/resources directory. For example, you can use the `