I'm using the following code to recognize test classes in a project, the whole idea is to find test classes and to compare the amount of test code with the production code! Here is a piece of my code which is responsible to find test class and count the lines:
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 on several projects, I realized that the idea of finding test classes that contain Unit
or EasyMock
or Mockito
is not the best practice to find test classes, as several projects use their own test methods! So the question is there a better way than mine to define test classes?
Thanks