Search code examples
javaunit-testingenumsemma

How to get full Emma coverage report on enum singletons?


It is possible to guarantee a unique instance of an object with enums in Java as following:

public enum EmmaTest {

    ;

    public static int someStaticMethod() {
        return 33;
    }

}

How can one implement 100% Emma test coverage on such objects? Is it possible? Or is it possible to tell Emma to ignore some methods?

The best I can get is:

enter image description here


Solution

  • Your EmmaTest is not a singleton. There is 0 instance of EmmaTest, so its constructor is never used, and there is no way to call valueOf with a valid value.

    BTW: do you really fear that valueOf or the default constructor might have a bug? Why do you want 100% coverage?