Domanda

I am working with EclEmma for the first time, and I noticed that the header for my main class is never getting coverage. Everything within the main method is green, but the header itself "public class Main" is always red.

In an attempt to find the source of the problem, I created a new class that only prints a string:

public class TestClass
{
    public static void main(String[] args)
    {
        System.out.println("Hello, World.");
    }
}

But I'm still getting no coverage on the header. 'public class TestClass' is coming up red.

I've tried searching for any issues related to what I'm seeing, but I can't seem to find anything. :( Anyone have any suggestions?

È stato utile?

Soluzione

The class header is not covered because you have not instantiated an object of the class. main() is static and thus does not require a TestClass instance.

Add the line shown below, and your class header will go green.

public class TestClass
{
    public static void main(String[] args)
    {
        TestClas tc = new TestClass();  // add this line
        System.out.println("Hello, World.");
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top