I use the following code to recognize test classes in a project, the whole idea is to find test classes and compare the amount of test code with production code! Here is the part of my code that is responsible for finding the test class and counting strings:
for (File f : list) {
if (f.isDirectory()) {
walk(f.getAbsolutePath());
}
if (f.getName().endsWith(".java")) {
System.out.println("File:" + f.getName());
countFiles++;
Scanner testScanner = new Scanner(f);
while (testScanner.hasNextLine()) {
String test = testScanner.nextLine();
if (test.contains("org.junit") || test.contains("org.mockito") || test.contains("org.easymock")) {
hasTestLines = true;
// break;
}
testCounter++;
}
But after running the code in several projects, I realized that the idea of finding test classes containing Uniteither EasyMockor Mockitois not the best practice for finding test classes, since several projects use their own test methods! So the question is to better define test classes?
thank
source
share