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 开发者_Python百科to ignore some methods?
The best I can get is:
Adding the line below to any test fixed it the code coverage for me:
MyEnum.valueOf(MyEnum.VALUE.toString());
Clearly the debate on the value of this is different to the actual solution. I too have a requirement for 100% coverage which was falling down due to the constructor of the enum not being called. Adding the above to a test resolved that for me without any clever reflection etc...
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?
精彩评论