I need to use JUnit 5 to test all Foo.java in different folders. All these Foo.java have implemented the same method interfaces (but with different method implementations). Suppose they don't belong to any package (i.e., there is no package xxx; on top of each file)
dir1
- Foo.java
dir2
- Foo.java
dir3
- Foo.java
I used IntelliJ IDEA + JUnit 5 + JDK 17 and have created a standard JUnit project.
I already have a JUnit test that works for each single .java file (cuz they all implemented the same set of methods with identical method signatures/APIs), if I put any individual .java file in the project src folder.
Yet, the problem is, all these directories dir* and .java files are not related to this project; they are stored somewhere else outside of the JUnit project's path.
In this case, how can I automatically test all of these .java files?
(I guess I need to programmatically traverse these files, compile them to .class, and use Java Reflections to instantiate objects using the .class file, then proceed the tests as usual. I wonder whether this is the way to go, or if there is any better approach.)