You need to sign in to do that
Don't have an account?
T.Rossi
testing code coverage for Interface
I have a simple class like this:
public class OuterClass { public virtual interface MyInterface{ Map<String, List<String>> method1(Blob b); Map<String, Map<String, List<String>>> method2(Map<String, Blob> m); void method3(String external_id); } }
I then have another class which implements this Interface. The implementation class can be tested correctly with code covarage, but this class (OuterClass) always remains with 0% code coverage.
2 questions:
A- how can I test my interface?
B- is it possible to create an Interface without the OuterClass?
Any help is welcome, thanks in advance,
T.
A) The interface itself will have 0% coverage. This is because there are no lines to cover; interfaces can't be directly executed, so they can't be directly tested. This doesn't affect the '75%' rule, because it adds zero lines of covered AND uncovered code.
B) You can indeed create an interface without a class. This file is built the same as a class (e.g. "public interface MyInterfaceName"). Coverage for the interface will still appear as 0% (0 covered/0 total), but again, this won't affect your package's overall code coverage performance.
As a proof of concept, I wrote a simple class that tests itself:
This class, after testing, shows as "100% (1/1)" under code covered. The only line highlighted blue is line 7 (public void asdf() ... ). You may accept this as confirmation that the outer class did not have testing requirements, and testing just the implementation classes is sufficient.
All Answers
A) The interface itself will have 0% coverage. This is because there are no lines to cover; interfaces can't be directly executed, so they can't be directly tested. This doesn't affect the '75%' rule, because it adds zero lines of covered AND uncovered code.
B) You can indeed create an interface without a class. This file is built the same as a class (e.g. "public interface MyInterfaceName"). Coverage for the interface will still appear as 0% (0 covered/0 total), but again, this won't affect your package's overall code coverage performance.
As a proof of concept, I wrote a simple class that tests itself:
This class, after testing, shows as "100% (1/1)" under code covered. The only line highlighted blue is line 7 (public void asdf() ... ). You may accept this as confirmation that the outer class did not have testing requirements, and testing just the implementation classes is sufficient.
thank you very much! I agree it wouldn't make a lot of sense to test an interface:)