From: SourceForge.net <no...@so...> - 2009-03-03 11:03:28
|
Feature Requests item #1959691, was opened at 2008-05-07 18:18 Message generated for change (Comment added) made by nobody You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=720018&aid=1959691&group_id=130558 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 6 Private: No Submitted By: John Lewis (lewijw) Assigned to: Nobody/Anonymous (nobody) Summary: Better Handling of Asserts Initial Comment: Ian Dickinson wrote: Sorry if this has been asked before; I did look in the archives but couldn't find anything. I'm getting low branch coverage on code that includes java asserts to encode invariants. For example: public void setFoo( String foo ) { assert foo != null; this.foo = foo; } @Test public void testSetFoo() { new MockFoo.setFoo( "bar" ); } @Test (expected=java.lang.AssertionError.class) public void testSetFoo() { new MockFoo().setFoo( null ); } I can execute both tests successfully, but cobertura will tell me that line with the assert was executed twice but did not traverse all branches. I'm passing -ea to the JVM to enable the assertions, which I can see is working since the tests themselves all pass. I'm using the cobertura 1.9 plugin for Maven2 on Java6 (I've tried both 6u6 and 6u4). Any suggestions? Thanks, Ian Jeffrey Bennett replied: To get full coverage, you'd need to run 3 tests: 1.) Asserts off 2.) Asserts on, conditional true 3.) Asserts on, conditional false You've done #2 and #3 To my knowledge, there's no good way of doing all 3 tests leading to a source of friction between Cobertura and asserts. Ian replied: OK, I understand. Would it be possible to have the branch coverage algorithm take this into account? I don't know if the VM args are captured in the .ser file, but if so it might be possible (I'm guessing here, I admit) for the branch coverage calculator to note that there are two possible worlds (your #1 vs #2 + #3), and depending which one is the "real" world adjust the statistics so that the code either tests one of the one possible branches, or two of the possible two. And if that isn't impossible, can I make it a feature request please? :-) ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2009-03-03 11:03 Message: Hi, Ditto - I'm using the Maven 2 plugin and would like to be able to disable assertions for the surefire run that cobertura uses. I checked the source and haven't found any obvious way... is there a known workaround (other than doing it manually) for this? Thanks! ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2008-12-02 22:44 Message: +1. At least provide an option to just automatically set assertion lines to green or exclude/ignore them. It's simply not practical to do 1+2+3 as described above. ---------------------------------------------------------------------- Comment By: Alan Gutierrez (alangutierrez) Date: 2008-06-03 13:19 Message: Logged In: YES user_id=2089590 Originator: NO Please implement this feature. Ideally, Cobertura would not expect to see #3 even when asserts were on. An assert is a condition that should never be true. A very fruitless execerise to test the Java assert mechanism. Certainly, running Cobertura with asserts off should only test #1 and not expect #2 or #3. I would be so happy to see this implemented. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=720018&aid=1959691&group_id=130558 |