samedi 27 février 2016

Best way to recognize test classes?

I am building a program that recognizes test classes and gives the coder an idea how much test code he wrote compared to the actual source code. My question is how can I make the program recognize a test class despite the type of tests that has been used? what is the main sign that you may find in a test class? Is it the @Test notation? If so how to handle it?

This is a piece of code of a class that I made to recognize test classes:

public void walk(String path) throws FileNotFoundException {
    int countFiles = 0;
    File root = new File(path);
    File[] list = root.listFiles();
    if (list == null) {
        return;
    }

    for (File f : list) {
        if (f.isDirectory()) {
            walk(f.getAbsolutePath());
        }

        if (f.getName().endsWith(".java")) {

            System.out.println("File:" + f.getName());
               Scanner sc2 = new Scanner(f);

            while (sc2.hasNextLine()) {

                count++;

                String str = sc2.nextLine();

                for (int i = 0; i < str.length(); i++) {
                    if(str.equals("@Test")){
                    System.out.println("this a test clsee!");
                }

But unfortunately my idea is not working. So what can I do?

Aucun commentaire:

Enregistrer un commentaire