From: SourceForge.net <no...@so...> - 2008-05-07 18:18:42
|
Feature Requests item #1959691, was opened at 2008-05-07 13:18 Message generated for change (Tracker Item Submitted) made by Item Submitter 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? :-) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=720018&aid=1959691&group_id=130558 |