Re: Test becomes uncovered when run in larger group

View: New views
11 Messages — Rating Filter:   Alert me  

Re: Test becomes uncovered when run in larger group

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's obvious from the console output that the test isn't being run:

[cobertura-instrument] Instrument time: 1719ms
test:
    [junit] Running com.jimandlisa.testutils.tests.AssertTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.141
sec
    [junit] Cobertura: Loaded information on 76 classes.
    [junit] Cobertura: Saved information on 76 classes.
    [junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.219
sec
    [junit] Cobertura: Loaded information on 76 classes.
    [junit] Cobertura: Saved information on 76 classes.
    [junit] Running com.jimandlisa.testutils.tests.ExceptionUtilsTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172
sec
    [junit] Cobertura: Loaded information on 76 classes.
    [junit] Cobertura: Saved information on 76 classes.
    [junit] Running com.jimandlisa.testutils.tests.ReflectionUtilsTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172
sec
    [junit] Cobertura: Loaded information on 76 classes.
    [junit] Cobertura: Saved information on 76 classes.

But when I change the ant script to just run the two tests, then the
output looks like this:

test:
    [junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.234
sec
    [junit] Cobertura: Loaded information on 76 classes.
    [junit] Cobertura: Saved information on 76 classes.
    [junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest2
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.156
sec
    [junit] Cobertura: Loaded information on 76 classes.
    [junit] Cobertura: Saved information on 76 classes.

Nothing is changed except for the ant script.

If it runs the tests with one wildcard pattern, why not the other,
when one is a subset of the other?

----- Original Message -----
From: "Jim Showalter" <jim@...>
To: <cobertura-devel@...>
Sent: Saturday, August 29, 2009 8:01 PM
Subject: Test becomes uncovered when run in larger group


> When I have the ant script set like this:
>
>    <target name="test" depends="instrument">
>        <junit fork="yes" printsummary="yes" dir="${basedir}"
> failureProperty="test.failed">
>            <classpath>
>                <pathelement path="${instrumented.dir}"/>
>                <pathelement path="${target.dir}"/>
>                <path refid="executing.classpath"/>
>            </classpath>
>            <formatter type="xml"/>
>            <test name="${testcase}" todir="${reports.xml.dir}"
> if="testcase"/>
>            <batchtest todir="${reports.xml.dir}" unless="testcase">
>                <fileset dir="${test.dir}">
>                    <include
> name="**/testutils/tests/*ErrorCodeUtilsTest*.java"/>
>                </fileset>
>            </batchtest>
>            <assertions>
>              <enable/>
>            </assertions>
>        </junit>
>        <junitreport todir="${reports.xml.dir}">
>            <fileset dir="${reports.xml.dir}">
>                <include name="TEST-*.xml"/>
>            </fileset>
>            <report format="frames" todir="${reports.html.dir}"/>
>        </junitreport>
>    </target>
>
> then ErrorCodeUtilsTest2 is covered (see Covered.png, attached).
>
> But when I change the ant script to run more tests:
>
>    <target name="test" depends="instrument">
>        <junit fork="yes" printsummary="yes" dir="${basedir}"
> failureProperty="test.failed">
>            <classpath>
>                <pathelement path="${instrumented.dir}"/>
>                <pathelement path="${target.dir}"/>
>                <path refid="executing.classpath"/>
>            </classpath>
>            <formatter type="xml"/>
>            <test name="${testcase}" todir="${reports.xml.dir}"
> if="testcase"/>
>            <batchtest todir="${reports.xml.dir}" unless="testcase">
>                <fileset dir="${test.dir}">
>                    <include name="**/testutils/tests/*Test.java"/>
>                </fileset>
>            </batchtest>
>            <assertions>
>              <enable/>
>            </assertions>
>        </junit>
>        <junitreport todir="${reports.xml.dir}">
>            <fileset dir="${reports.xml.dir}">
>                <include name="TEST-*.xml"/>
>            </fileset>
>            <report format="frames" todir="${reports.html.dir}"/>
>        </junitreport>
>    </target>
>
> the test becomes uncovered, per the second screenshot.
>
> Nothing else is changed.
>
> What is going on?
>
> ---------------------------------
> Jim Showalter
> http://jimshowalter.blogspot.com
>


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Parent Message unknown Re: Test becomes uncovered when run in larger group

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Even modifying the ant task doesn't help:

            <batchtest todir="${reports.xml.dir}" unless="testcase">
                <fileset dir="${test.dir}">
                    <include name="**/testutils/tests/*Test.java"/>
                </fileset>
                <fileset dir="${test.dir}">
                    <include
name="**/testutils/tests/ErrorCodeUtilsTest2.java"/>
                </fileset>
            </batchtest>

----- Original Message -----
From: "Jim Showalter" <jim@...>
To: <cobertura-devel@...>
Sent: Saturday, August 29, 2009 8:24 PM
Subject: Re: Test becomes uncovered when run in larger group


> It's obvious from the console output that the test isn't being run:
>
> [cobertura-instrument] Instrument time: 1719ms
> test:
>    [junit] Running com.jimandlisa.testutils.tests.AssertTest
>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.141
> sec
>    [junit] Cobertura: Loaded information on 76 classes.
>    [junit] Cobertura: Saved information on 76 classes.
>    [junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest
>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.219
> sec
>    [junit] Cobertura: Loaded information on 76 classes.
>    [junit] Cobertura: Saved information on 76 classes.
>    [junit] Running com.jimandlisa.testutils.tests.ExceptionUtilsTest
>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172
> sec
>    [junit] Cobertura: Loaded information on 76 classes.
>    [junit] Cobertura: Saved information on 76 classes.
>    [junit] Running
> com.jimandlisa.testutils.tests.ReflectionUtilsTest
>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172
> sec
>    [junit] Cobertura: Loaded information on 76 classes.
>    [junit] Cobertura: Saved information on 76 classes.
>
> But when I change the ant script to just run the two tests, then the
> output looks like this:
>
> test:
>    [junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest
>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.234
> sec
>    [junit] Cobertura: Loaded information on 76 classes.
>    [junit] Cobertura: Saved information on 76 classes.
>    [junit] Running
> com.jimandlisa.testutils.tests.ErrorCodeUtilsTest2
>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.156
> sec
>    [junit] Cobertura: Loaded information on 76 classes.
>    [junit] Cobertura: Saved information on 76 classes.
>
> Nothing is changed except for the ant script.
>
> If it runs the tests with one wildcard pattern, why not the other,
> when one is a subset of the other?
>
> ----- Original Message -----
> From: "Jim Showalter" <jim@...>
> To: <cobertura-devel@...>
> Sent: Saturday, August 29, 2009 8:01 PM
> Subject: Test becomes uncovered when run in larger group
>
>
>> When I have the ant script set like this:
>>
>>    <target name="test" depends="instrument">
>>        <junit fork="yes" printsummary="yes" dir="${basedir}"
>> failureProperty="test.failed">
>>            <classpath>
>>                <pathelement path="${instrumented.dir}"/>
>>                <pathelement path="${target.dir}"/>
>>                <path refid="executing.classpath"/>
>>            </classpath>
>>            <formatter type="xml"/>
>>            <test name="${testcase}" todir="${reports.xml.dir}"
>> if="testcase"/>
>>            <batchtest todir="${reports.xml.dir}" unless="testcase">
>>                <fileset dir="${test.dir}">
>>                    <include
>> name="**/testutils/tests/*ErrorCodeUtilsTest*.java"/>
>>                </fileset>
>>            </batchtest>
>>            <assertions>
>>              <enable/>
>>            </assertions>
>>        </junit>
>>        <junitreport todir="${reports.xml.dir}">
>>            <fileset dir="${reports.xml.dir}">
>>                <include name="TEST-*.xml"/>
>>            </fileset>
>>            <report format="frames" todir="${reports.html.dir}"/>
>>        </junitreport>
>>    </target>
>>
>> then ErrorCodeUtilsTest2 is covered (see Covered.png, attached).
>>
>> But when I change the ant script to run more tests:
>>
>>    <target name="test" depends="instrument">
>>        <junit fork="yes" printsummary="yes" dir="${basedir}"
>> failureProperty="test.failed">
>>            <classpath>
>>                <pathelement path="${instrumented.dir}"/>
>>                <pathelement path="${target.dir}"/>
>>                <path refid="executing.classpath"/>
>>            </classpath>
>>            <formatter type="xml"/>
>>            <test name="${testcase}" todir="${reports.xml.dir}"
>> if="testcase"/>
>>            <batchtest todir="${reports.xml.dir}" unless="testcase">
>>                <fileset dir="${test.dir}">
>>                    <include name="**/testutils/tests/*Test.java"/>
>>                </fileset>
>>            </batchtest>
>>            <assertions>
>>              <enable/>
>>            </assertions>
>>        </junit>
>>        <junitreport todir="${reports.xml.dir}">
>>            <fileset dir="${reports.xml.dir}">
>>                <include name="TEST-*.xml"/>
>>            </fileset>
>>            <report format="frames" todir="${reports.html.dir}"/>
>>        </junitreport>
>>    </target>
>>
>> the test becomes uncovered, per the second screenshot.
>>
>> Nothing else is changed.
>>
>> What is going on?
>>
>> ---------------------------------
>> Jim Showalter
>> http://jimshowalter.blogspot.com
>>
>


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: Test becomes uncovered when run in larger group

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Idiot.

It ends in 2, so it flunks the pattern.

----- Original Message -----
From: "Jim Showalter" <jim@...>
To: <cobertura-devel@...>
Sent: Saturday, August 29, 2009 8:35 PM
Subject: Re: [Cobertura-devel] Test becomes uncovered when run in
larger group


> Even modifying the ant task doesn't help:
>
>            <batchtest todir="${reports.xml.dir}" unless="testcase">
>                <fileset dir="${test.dir}">
>                    <include name="**/testutils/tests/*Test.java"/>
>                </fileset>
>                <fileset dir="${test.dir}">
>                    <include
> name="**/testutils/tests/ErrorCodeUtilsTest2.java"/>
>                </fileset>
>            </batchtest>
>
> ----- Original Message -----
> From: "Jim Showalter" <jim@...>
> To: <cobertura-devel@...>
> Sent: Saturday, August 29, 2009 8:24 PM
> Subject: Re: Test becomes uncovered when run in larger group
>
>
>> It's obvious from the console output that the test isn't being run:
>>
>> [cobertura-instrument] Instrument time: 1719ms
>> test:
>>    [junit] Running com.jimandlisa.testutils.tests.AssertTest
>>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed:
>> 0.141
>> sec
>>    [junit] Cobertura: Loaded information on 76 classes.
>>    [junit] Cobertura: Saved information on 76 classes.
>>    [junit] Running
>> com.jimandlisa.testutils.tests.ErrorCodeUtilsTest
>>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed:
>> 0.219
>> sec
>>    [junit] Cobertura: Loaded information on 76 classes.
>>    [junit] Cobertura: Saved information on 76 classes.
>>    [junit] Running
>> com.jimandlisa.testutils.tests.ExceptionUtilsTest
>>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed:
>> 0.172
>> sec
>>    [junit] Cobertura: Loaded information on 76 classes.
>>    [junit] Cobertura: Saved information on 76 classes.
>>    [junit] Running
>> com.jimandlisa.testutils.tests.ReflectionUtilsTest
>>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed:
>> 0.172
>> sec
>>    [junit] Cobertura: Loaded information on 76 classes.
>>    [junit] Cobertura: Saved information on 76 classes.
>>
>> But when I change the ant script to just run the two tests, then
>> the
>> output looks like this:
>>
>> test:
>>    [junit] Running
>> com.jimandlisa.testutils.tests.ErrorCodeUtilsTest
>>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed:
>> 0.234
>> sec
>>    [junit] Cobertura: Loaded information on 76 classes.
>>    [junit] Cobertura: Saved information on 76 classes.
>>    [junit] Running
>> com.jimandlisa.testutils.tests.ErrorCodeUtilsTest2
>>    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed:
>> 0.156
>> sec
>>    [junit] Cobertura: Loaded information on 76 classes.
>>    [junit] Cobertura: Saved information on 76 classes.
>>
>> Nothing is changed except for the ant script.
>>
>> If it runs the tests with one wildcard pattern, why not the other,
>> when one is a subset of the other?
>>
>> ----- Original Message -----
>> From: "Jim Showalter" <jim@...>
>> To: <cobertura-devel@...>
>> Sent: Saturday, August 29, 2009 8:01 PM
>> Subject: Test becomes uncovered when run in larger group
>>
>>
>>> When I have the ant script set like this:
>>>
>>>    <target name="test" depends="instrument">
>>>        <junit fork="yes" printsummary="yes" dir="${basedir}"
>>> failureProperty="test.failed">
>>>            <classpath>
>>>                <pathelement path="${instrumented.dir}"/>
>>>                <pathelement path="${target.dir}"/>
>>>                <path refid="executing.classpath"/>
>>>            </classpath>
>>>            <formatter type="xml"/>
>>>            <test name="${testcase}" todir="${reports.xml.dir}"
>>> if="testcase"/>
>>>            <batchtest todir="${reports.xml.dir}"
>>> unless="testcase">
>>>                <fileset dir="${test.dir}">
>>>                    <include
>>> name="**/testutils/tests/*ErrorCodeUtilsTest*.java"/>
>>>                </fileset>
>>>            </batchtest>
>>>            <assertions>
>>>              <enable/>
>>>            </assertions>
>>>        </junit>
>>>        <junitreport todir="${reports.xml.dir}">
>>>            <fileset dir="${reports.xml.dir}">
>>>                <include name="TEST-*.xml"/>
>>>            </fileset>
>>>            <report format="frames" todir="${reports.html.dir}"/>
>>>        </junitreport>
>>>    </target>
>>>
>>> then ErrorCodeUtilsTest2 is covered (see Covered.png, attached).
>>>
>>> But when I change the ant script to run more tests:
>>>
>>>    <target name="test" depends="instrument">
>>>        <junit fork="yes" printsummary="yes" dir="${basedir}"
>>> failureProperty="test.failed">
>>>            <classpath>
>>>                <pathelement path="${instrumented.dir}"/>
>>>                <pathelement path="${target.dir}"/>
>>>                <path refid="executing.classpath"/>
>>>            </classpath>
>>>            <formatter type="xml"/>
>>>            <test name="${testcase}" todir="${reports.xml.dir}"
>>> if="testcase"/>
>>>            <batchtest todir="${reports.xml.dir}"
>>> unless="testcase">
>>>                <fileset dir="${test.dir}">
>>>                    <include name="**/testutils/tests/*Test.java"/>
>>>                </fileset>
>>>            </batchtest>
>>>            <assertions>
>>>              <enable/>
>>>            </assertions>
>>>        </junit>
>>>        <junitreport todir="${reports.xml.dir}">
>>>            <fileset dir="${reports.xml.dir}">
>>>                <include name="TEST-*.xml"/>
>>>            </fileset>
>>>            <report format="frames" todir="${reports.html.dir}"/>
>>>        </junitreport>
>>>    </target>
>>>
>>> the test becomes uncovered, per the second screenshot.
>>>
>>> Nothing else is changed.
>>>
>>> What is going on?
>>>
>>> ---------------------------------
>>> Jim Showalter
>>> http://jimshowalter.blogspot.com
>>>
>>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

When junit fork is set to "no", reports show zero coverage

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I can't run the tests in separate VMs, because they need to share a
static singleton.

I changed the ant script to specify fork="no", and removed the
dir="${basedir}" because now that's ignored, but now when the tests
run they produce JUnit output, but the coverage reports show zero
coverage.

What's the trick for setting fork="no" but still getting coverage
reports?

---------------------------------

Jim Showalter
http://jimshowalter.blogspot.com 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: When junit fork is set to "no", reports show zero coverage

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The FAQ says:

"When I generate coverage reports, why do they always show 0% coverage
everywhere?

Cobertura is probably using the wrong .ser file when generating the
reports. When you instrument your classes, Cobertura generates a .ser
file containing basic information about each class. As your tests run,
Cobertura adds additional information to this same data file. If the
instrumented classes can not find the data file when running then they
will create a new one. It is important that you use the same
cobertura.ser file when instrumenting, running, and generating
reports.

The best way to do this is to specify the location of the data file
when running your tests. You should pass
the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
sysproperty to the JUnit task."

I have tried to do that in the ant script:

    <target name="test" depends="instrument">
        <junit fork="no" printsummary="yes"
failureProperty="test.failed">
            <sysproperty key="net.sourceforge.cobertura.datafile"
value="${basedir}/cobertura.ser"/>
            <classpath>
                <pathelement path="${instrumented.dir}"/>
                <pathelement path="${target.dir}"/>
                <path refid="executing.classpath"/>
            </classpath>
            <formatter type="xml"/>
            <test name="${testcase}" todir="${reports.xml.dir}"
if="testcase"/>
            <batchtest todir="${reports.xml.dir}" unless="testcase">
                <fileset dir="${test.dir}">
                    <include name="**/testutils/tests/*Test.java"/>
                </fileset>
            </batchtest>
            <assertions>
                <enable/>
            </assertions>
        </junit>
        <junitreport todir="${reports.xml.dir}">
            <fileset dir="${reports.xml.dir}">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${reports.html.dir}"/>
        </junitreport>
    </target>

But it seems to have no effect. The coverage reports are still empty.

What is the trick to getting this to work?

----- Original Message -----
From: "Jim Showalter" <jim@...>
To: <cobertura-devel@...>
Sent: Saturday, August 29, 2009 9:18 PM
Subject: [Cobertura-devel] When junit fork is set to "no",reports show
zero coverage


>I can't run the tests in separate VMs, because they need to share a
> static singleton.
>
> I changed the ant script to specify fork="no", and removed the
> dir="${basedir}" because now that's ignored, but now when the tests
> run they produce JUnit output, but the coverage reports show zero
> coverage.
>
> What's the trick for setting fork="no" but still getting coverage
> reports?
>
> ---------------------------------
>
> Jim Showalter
> http://jimshowalter.blogspot.com
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: When junit fork is set to "no", reports show zero coverage

by Peter Reilly-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try forkmode = once.
With fork=no, the jvm does not exit n

On Sun, Aug 30, 2009 at 6:45 AM, Jim Showalter<jim@...> wrote:

> The FAQ says:
>
> "When I generate coverage reports, why do they always show 0% coverage
> everywhere?
>
> Cobertura is probably using the wrong .ser file when generating the
> reports. When you instrument your classes, Cobertura generates a .ser
> file containing basic information about each class. As your tests run,
> Cobertura adds additional information to this same data file. If the
> instrumented classes can not find the data file when running then they
> will create a new one. It is important that you use the same
> cobertura.ser file when instrumenting, running, and generating
> reports.
>
> The best way to do this is to specify the location of the data file
> when running your tests. You should pass
> the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
> sysproperty to the JUnit task."
>
> I have tried to do that in the ant script:
>
>    <target name="test" depends="instrument">
>        <junit fork="no" printsummary="yes"
> failureProperty="test.failed">
>            <sysproperty key="net.sourceforge.cobertura.datafile"
> value="${basedir}/cobertura.ser"/>
>            <classpath>
>                <pathelement path="${instrumented.dir}"/>
>                <pathelement path="${target.dir}"/>
>                <path refid="executing.classpath"/>
>            </classpath>
>            <formatter type="xml"/>
>            <test name="${testcase}" todir="${reports.xml.dir}"
> if="testcase"/>
>            <batchtest todir="${reports.xml.dir}" unless="testcase">
>                <fileset dir="${test.dir}">
>                    <include name="**/testutils/tests/*Test.java"/>
>                </fileset>
>            </batchtest>
>            <assertions>
>                <enable/>
>            </assertions>
>        </junit>
>        <junitreport todir="${reports.xml.dir}">
>            <fileset dir="${reports.xml.dir}">
>                <include name="TEST-*.xml"/>
>            </fileset>
>            <report format="frames" todir="${reports.html.dir}"/>
>        </junitreport>
>    </target>
>
> But it seems to have no effect. The coverage reports are still empty.
>
> What is the trick to getting this to work?
>
> ----- Original Message -----
> From: "Jim Showalter" <jim@...>
> To: <cobertura-devel@...>
> Sent: Saturday, August 29, 2009 9:18 PM
> Subject: [Cobertura-devel] When junit fork is set to "no",reports show
> zero coverage
>
>
>>I can't run the tests in separate VMs, because they need to share a
>> static singleton.
>>
>> I changed the ant script to specify fork="no", and removed the
>> dir="${basedir}" because now that's ignored, but now when the tests
>> run they produce JUnit output, but the coverage reports show zero
>> coverage.
>>
>> What's the trick for setting fork="no" but still getting coverage
>> reports?
>>
>> ---------------------------------
>>
>> Jim Showalter
>> http://jimshowalter.blogspot.com
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and
>> focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Cobertura-devel mailing list
>> Cobertura-devel@...
>> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: When junit fork is set to "no", reports show zero coverage

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you very much for responding!

I changed fork to once and it still reports zero coverage.

If I change fork to yes, it reports near 100% coverage, except for one
line, which requires that all tests run in the same VM in order to be
covered.

So I'm still stuck.

The problem, I think, is that when I change fork to once, or to no,
then I see these warnings in the output about the dir attribute, but I
don't know how to set the dir per the FAQ:

"The best way to do this is to specify the location of the data file
when running your tests. You should pass
the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
sysproperty to the JUnit task. "

What would be really helpful is an example of an ant script that sets
the dir.

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.AbstractDatabaseTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.406 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.DatabaseExceptionTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.203 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.LoggerTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.047 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.SqlUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.015 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestCursorTest

[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.75 sec

[junit] Test com.jimandlisa.common.tests.TestCursorTest FAILED

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestDatabaseTest

[junit] Tests run: 1, Failures: 0, Errors: 2, Time elapsed: 0.203 sec

[junit] Test com.jimandlisa.common.tests.TestDatabaseTest FAILED

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestLoggerTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.AssertTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.063 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtils2Test

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.094 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.218 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ExceptionUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ReflectionUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.157 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.TestConstantsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.062 sec

----- Original Message -----
From: "Peter Reilly" <peter.kitt.reilly@...>
To: <cobertura-devel@...>
Sent: Thursday, September 03, 2009 11:48 PM
Subject: Re: [Cobertura-devel] When junit fork is set to "no",reports
show zero coverage


Try forkmode = once.
With fork=no, the jvm does not exit n

On Sun, Aug 30, 2009 at 6:45 AM, Jim Showalter<jim@...>
wrote:

> The FAQ says:
>
> "When I generate coverage reports, why do they always show 0%
> coverage
> everywhere?
>
> Cobertura is probably using the wrong .ser file when generating the
> reports. When you instrument your classes, Cobertura generates a
> .ser
> file containing basic information about each class. As your tests
> run,
> Cobertura adds additional information to this same data file. If the
> instrumented classes can not find the data file when running then
> they
> will create a new one. It is important that you use the same
> cobertura.ser file when instrumenting, running, and generating
> reports.
>
> The best way to do this is to specify the location of the data file
> when running your tests. You should pass
> the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
> sysproperty to the JUnit task."
>
> I have tried to do that in the ant script:
>
> <target name="test" depends="instrument">
> <junit fork="no" printsummary="yes"
> failureProperty="test.failed">
> <sysproperty key="net.sourceforge.cobertura.datafile"
> value="${basedir}/cobertura.ser"/>
> <classpath>
> <pathelement path="${instrumented.dir}"/>
> <pathelement path="${target.dir}"/>
> <path refid="executing.classpath"/>
> </classpath>
> <formatter type="xml"/>
> <test name="${testcase}" todir="${reports.xml.dir}"
> if="testcase"/>
> <batchtest todir="${reports.xml.dir}" unless="testcase">
> <fileset dir="${test.dir}">
> <include name="**/testutils/tests/*Test.java"/>
> </fileset>
> </batchtest>
> <assertions>
> <enable/>
> </assertions>
> </junit>
> <junitreport todir="${reports.xml.dir}">
> <fileset dir="${reports.xml.dir}">
> <include name="TEST-*.xml"/>
> </fileset>
> <report format="frames" todir="${reports.html.dir}"/>
> </junitreport>
> </target>
>
> But it seems to have no effect. The coverage reports are still
> empty.
>
> What is the trick to getting this to work?
>
> ----- Original Message -----
> From: "Jim Showalter" <jim@...>
> To: <cobertura-devel@...>
> Sent: Saturday, August 29, 2009 9:18 PM
> Subject: [Cobertura-devel] When junit fork is set to "no",reports
> show
> zero coverage
>
>
>>I can't run the tests in separate VMs, because they need to share a
>> static singleton.
>>
>> I changed the ant script to specify fork="no", and removed the
>> dir="${basedir}" because now that's ignored, but now when the tests
>> run they produce JUnit output, but the coverage reports show zero
>> coverage.
>>
>> What's the trick for setting fork="no" but still getting coverage
>> reports?
>>
>> ---------------------------------
>>
>> Jim Showalter
>> http://jimshowalter.blogspot.com
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports
>> 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment -
>> and
>> focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Cobertura-devel mailing list
>> Cobertura-devel@...
>> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: When junit fork is set to "no", reports show zero coverage

by John W. Lewis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Jim,

Thanks for your blog post!

Peter was suggesting you use forkmode which only makes sense if you set fork to yes.

But, you are trying to set fork to no.   That is something no Cobertura user has needed to do so far.

I want to put some thought into your question, but at the moment I am trying to get out a new release of Cobertura that has the latest Javancss in it.   I think this will probably solve your second problem.

I'll have to get back with you after I have tried out the Cobertura release candidate on the test system I maintain.   Hopefully some time next week...

John

-----Original Message-----
From: Jim Showalter [mailto:jim@...]
Sent: Friday, September 04, 2009 3:08 AM
To: Peter Reilly; cobertura-devel@...
Subject: Re: [Cobertura-devel] When junit fork is set to "no", reports show zero coverage

Thank you very much for responding!

I changed fork to once and it still reports zero coverage.

If I change fork to yes, it reports near 100% coverage, except for one
line, which requires that all tests run in the same VM in order to be
covered.

So I'm still stuck.

The problem, I think, is that when I change fork to once, or to no,
then I see these warnings in the output about the dir attribute, but I
don't know how to set the dir per the FAQ:

"The best way to do this is to specify the location of the data file
when running your tests. You should pass
the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
sysproperty to the JUnit task. "

What would be really helpful is an example of an ant script that sets
the dir.

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.AbstractDatabaseTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.406 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.DatabaseExceptionTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.203 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.LoggerTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.047 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.SqlUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.015 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestCursorTest

[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.75 sec

[junit] Test com.jimandlisa.common.tests.TestCursorTest FAILED

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestDatabaseTest

[junit] Tests run: 1, Failures: 0, Errors: 2, Time elapsed: 0.203 sec

[junit] Test com.jimandlisa.common.tests.TestDatabaseTest FAILED

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestLoggerTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.AssertTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.063 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtils2Test

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.094 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.218 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ExceptionUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ReflectionUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.157 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.TestConstantsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.062 sec

----- Original Message -----
From: "Peter Reilly" <peter.kitt.reilly@...>
To: <cobertura-devel@...>
Sent: Thursday, September 03, 2009 11:48 PM
Subject: Re: [Cobertura-devel] When junit fork is set to "no",reports
show zero coverage


Try forkmode = once.
With fork=no, the jvm does not exit n

On Sun, Aug 30, 2009 at 6:45 AM, Jim Showalter<jim@...>
wrote:

> The FAQ says:
>
> "When I generate coverage reports, why do they always show 0%
> coverage
> everywhere?
>
> Cobertura is probably using the wrong .ser file when generating the
> reports. When you instrument your classes, Cobertura generates a
> .ser
> file containing basic information about each class. As your tests
> run,
> Cobertura adds additional information to this same data file. If the
> instrumented classes can not find the data file when running then
> they
> will create a new one. It is important that you use the same
> cobertura.ser file when instrumenting, running, and generating
> reports.
>
> The best way to do this is to specify the location of the data file
> when running your tests. You should pass
> the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
> sysproperty to the JUnit task."
>
> I have tried to do that in the ant script:
>
> <target name="test" depends="instrument">
> <junit fork="no" printsummary="yes"
> failureProperty="test.failed">
> <sysproperty key="net.sourceforge.cobertura.datafile"
> value="${basedir}/cobertura.ser"/>
> <classpath>
> <pathelement path="${instrumented.dir}"/>
> <pathelement path="${target.dir}"/>
> <path refid="executing.classpath"/>
> </classpath>
> <formatter type="xml"/>
> <test name="${testcase}" todir="${reports.xml.dir}"
> if="testcase"/>
> <batchtest todir="${reports.xml.dir}" unless="testcase">
> <fileset dir="${test.dir}">
> <include name="**/testutils/tests/*Test.java"/>
> </fileset>
> </batchtest>
> <assertions>
> <enable/>
> </assertions>
> </junit>
> <junitreport todir="${reports.xml.dir}">
> <fileset dir="${reports.xml.dir}">
> <include name="TEST-*.xml"/>
> </fileset>
> <report format="frames" todir="${reports.html.dir}"/>
> </junitreport>
> </target>
>
> But it seems to have no effect. The coverage reports are still
> empty.
>
> What is the trick to getting this to work?
>
> ----- Original Message -----
> From: "Jim Showalter" <jim@...>
> To: <cobertura-devel@...>
> Sent: Saturday, August 29, 2009 9:18 PM
> Subject: [Cobertura-devel] When junit fork is set to "no",reports
> show
> zero coverage
>
>
>>I can't run the tests in separate VMs, because they need to share a
>> static singleton.
>>
>> I changed the ant script to specify fork="no", and removed the
>> dir="${basedir}" because now that's ignored, but now when the tests
>> run they produce JUnit output, but the coverage reports show zero
>> coverage.
>>
>> What's the trick for setting fork="no" but still getting coverage
>> reports?
>>
>> ---------------------------------
>>
>> Jim Showalter
>> http://jimshowalter.blogspot.com
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports
>> 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment -
>> and
>> focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Cobertura-devel mailing list
>> Cobertura-devel@...
>> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: When junit fork is set to "no", reports show zero coverage

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you for your response!

Let me describe the use case so you see why I have to run all of the
tests in one VM.

I'm writing a utility that tests that every error code defined by an
exception has been seen in a throw.

The API is below.

public final class ErrorCodeUtils
{
    /**
     * Parameterized constructor.
     * @param exceptionDefiningErrorCodes Class of the exception being
tested.
     * @param testClasses Classes testing the exception.
     * @param getErrorCodeMethodName Name of method that returns error
code. Method must have
     * an int return type, and no parameters.
     * @throws RuntimeException Problem encountered using reflection
to get method or error codes.
     * @throws IllegalArgumentException Exception class does not
define a method with the
     * specified name, or defines a method with the specified name,
but with parameters and/or
     * a non-int return type; or defines a public field that is not an
int.
     * @throws IllegalStateException Duplicate error code defined by
exception being tested.
     */
    public ErrorCodeUtils(
        final Class<? extends Throwable> exceptionDefiningErrorCodes,
        final Class<?>[] testClasses,
        final String getErrorCodeMethodName)...

    /**
     * Reports that a test has finished.
     * @throws IllegalArgumentException Calling class is not one of
the test classes.
     * @throws IllegalStateException Test class has already reported
finishing, or
     * this was the last test to finish and there is an untested error
code.
     * @throws RuntimeException Problem encountered getting finishing
class, or using
     * reflection to get error code.
     */
    public final synchronized void reportTestFinish()...

    /**
     * Determines whether specified exception matches expected type
and has expected error code
     * and message, or has root cause that matches expected type and
has expected error code
     * and message.
     * @param e Exception.
     * @param expectedErrorCode Expected error code.
     * @param matchMessage Part or whole of expected exception
message, or null if there is no
     * message or there is a message but it should be ignored.
     * @throws IllegalArgumentException Error code is undefined.
     * @throws RuntimeException Exception is null, or exception is not
null but exception or
     * root cause of exception doesn't match expected type, or matches
expected type but does
     * not have expected error code, or has expected error code but
match message is not null
     * and does not match exception message.
     */
    public final void assertIsExpectedException(
        final Throwable e,
        final int expectedErrorCode,
        final String matchMessage) throws RuntimeException..

    /**
     * Executes constructor for specified class and verifies that it
throws expected exception type
     * with expected error code.
     * @param classToConstruct Class to construct.
     * @param expectedErrorCode Expected error code.
     * @param matchMessage Part or whole of expected exception
message, or null if there is no message
     * or there is a message but it should be ignored.
     * @param parameters Parameters to constructor as ordered list of
type and object pairs, where the
     * type is the type of the parameter and the object is the value
of the argument to the parameter.
     * @throws IllegalArgumentException Error code is undefined.
     * @throws RuntimeException Exception is not thrown, or exception
is thrown but exception or root
     * cause of exception doesn't match expected type, or matches
expected type but does not have expected
     * error code, or has expected error code but match message is not
null and does not match exception
     * message.
     * <br>
     * Note: If the Class/Object parameter pairs are invalid,
InvalidArgumentException will be thrown
     * by the reflected call, which may or may not match the expected
exception; if it does match the
     * expected exception, the assert will pass, but it will be a
false negative--therefore, care must
     * be taken to supply valid parameter pairs.
     */
    public final void assertThrowsExpectedException(
        final Class<?> classToConstruct,
        final int expectedErrorCode, final String matchMessage,
        final Object... parameters) throws RuntimeException...

    /**
     * Executes specified static method and verifies that it throws
expected exception type with
     * expected error code.
     * @param classToInvoke Class to invoke static method on.
     * @param methodName Name of static method to invoke.
     * @param expectedErrorCode Expected error code.
     * @param matchMessage Part or whole of expected exception
message, or null if there is no message
     * or there is a message but it should be ignored.
     * @param parameters Parameters to static method as ordered list
of type and object pairs, where the
     * type is the type of the parameter and the object is the value
of the argument to the parameter.
     * @throws IllegalArgumentException Error code is undefined.
     * @throws RuntimeException Exception is not thrown, or exception
is thrown but exception or root
     * cause of exception doesn't match expected type, or matches
expected type but does not have expected
     * error code, or has expected error code but match message is not
null and does not match exception
     * message.
     * <br>
     * Note: If the Class/Object parameter pairs are invalid,
InvalidArgumentException will be thrown
     * by the reflected call, which may or may not match the expected
exception; if it does match the
     * expected exception, the assert will pass, but it will be a
false negative--therefore, care must
     * be taken to supply valid parameter pairs.
     */
    public final void assertThrowsExpectedException(
        final Class<?> classToInvoke, final String methodName,
        final int expectedErrorCode, final String matchMessage,
        final Object... parameters) throws RuntimeException...

    /**
     * Executes specified method and verifies that it throws expected
exception type with expected
     * error code.
     * @param target Object to invoke method on.
     * @param methodName Name of method to invoke.
     * @param expectedErrorCode Expected error code.
     * @param matchMessage Part or whole of expected exception
message, or null if there is no message
     * or there is a message but it should be ignored.
     * @param parameters Parameters to method as ordered list of type
and object pairs, where the
     * type is the type of the parameter and the object is the value
of the argument to the parameter.
     * @throws IllegalArgumentException Error code is undefined.
     * @throws RuntimeException Exception is not thrown, or exception
is thrown but exception or root
     * cause of exception doesn't match expected type, or matches
expected type but does not have expected
     * error code, or has expected error code but match message is not
null and does not match exception
     * message.
     * <br>
     * Note: If the Class/Object parameter pairs are invalid,
InvalidArgumentException will be thrown
     * by the reflected call, which may or may not match the expected
exception; if it does match the
     * expected exception, the assert will pass, but it will be a
false negative--therefore, care must
     * be taken to supply valid parameter pairs.
     */
    public final void assertThrowsExpectedException(
        final Object target, final String methodName,
        final int expectedErrorCode, final String matchMessage,
        final Object... parameters) throws RuntimeException...
}

To use it, a programmer defines a utility class and calls it from
their test:

package com.example;

public class ExampleException extends RuntimeException
{
    private int mErrorCode;

    ExampleException(String message, int errorCode, Throwable e)
    {
        super(message, e);

        mErrorCode = errorCode;
    }

    public static int ZeroLengthString = 0;

    public int getErrorCode()
    {
        return mErrorCode;
    }
}

package com.example;

public class Example
{
    private int count(String string)
    {
        // Deliberately not testing for null first so we can show how
to test for
        // an exception other than ExampleException.

        if ("".compareTo(string) == 0)
        {
            throw new ExampleException("Zero-length string",
ExampleException.ZeroLengthString, null);
        }

        return string.length();
    }
}

package com.example;

import com.jimandlisa.testutils.ErrorCodeUtils;

public class ExampleErrorCodeUtils
{
    private static ErrorCodeUtils sErrorCodeUtils = null;

    static synchronized ErrorCodeUtils getErrorCodeUtils()
    {
        if (sErrorCodeUtils == null)
        {
            sErrorCodeUtils =
                new ErrorCodeUtils(
                    ExampleException.class, new
Class<?>[]{ExampleTest.class}, "getErrorCode");
        }

        return sErrorCodeUtils;
    }

    public static void reportTestFinish()
    {
        getErrorCodeUtils().reportTestFinish();
    }
}

package com.example;

import org.junit.AfterClass;
import org.junit.Test;

import com.jimandlisa.testutils.Assert;
import com.jimandlisa.testutils.ExceptionUtils;
import com.jimandlisa.testutils.ReflectionUtils;

public class ExampleTest
{
    @Test
    public void testExample()
    {
        Example example = new Example();

        ExampleErrorCodeUtils.getErrorCodeUtils().assertThrowsExpectedException(
            example, "count",
            ExampleException.ZeroLengthString, "Zero-length string",
            String.class, "");
    }

    @AfterClass
    public static void finish()
    {
        ExampleErrorCodeUtils.reportTestFinish();
    }
}

Because the error-code util that keeps track of the calls is a static
singleton per VM, all the tests have to run in one VM. Otherwise, when
each test finishes and calls finish, the singleton in that test's VM
only sees that test finish. It needs to see all of the tests finish.

I can change it to write the test-finished statuses to a file, but
then I have to deal with file lock synchronization, etc.

----- Original Message -----
From: "John W. Lewis" <JohnW.Lewis@...>
To: "Jim Showalter" <jim@...>; "Peter Reilly"
<peter.kitt.reilly@...>; <cobertura-devel@...>
Sent: Friday, September 04, 2009 6:02 AM
Subject: RE: [Cobertura-devel] When junit fork is set to "no",reports
show zero coverage



Hi Jim,

Thanks for your blog post!

Peter was suggesting you use forkmode which only makes sense if you
set fork to yes.

But, you are trying to set fork to no.   That is something no
Cobertura user has needed to do so far.

I want to put some thought into your question, but at the moment I am
trying to get out a new release of Cobertura that has the latest
Javancss in it.   I think this will probably solve your second
problem.

I'll have to get back with you after I have tried out the Cobertura
release candidate on the test system I maintain.   Hopefully some time
next week...

John

-----Original Message-----
From: Jim Showalter [mailto:jim@...]
Sent: Friday, September 04, 2009 3:08 AM
To: Peter Reilly; cobertura-devel@...
Subject: Re: [Cobertura-devel] When junit fork is set to "no", reports
show zero coverage

Thank you very much for responding!

I changed fork to once and it still reports zero coverage.

If I change fork to yes, it reports near 100% coverage, except for one
line, which requires that all tests run in the same VM in order to be
covered.

So I'm still stuck.

The problem, I think, is that when I change fork to once, or to no,
then I see these warnings in the output about the dir attribute, but I
don't know how to set the dir per the FAQ:

"The best way to do this is to specify the location of the data file
when running your tests. You should pass
the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
sysproperty to the JUnit task. "

What would be really helpful is an example of an ant script that sets
the dir.

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.AbstractDatabaseTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.406 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.DatabaseExceptionTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.203 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.LoggerTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.047 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.SqlUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.015 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestCursorTest

[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.75 sec

[junit] Test com.jimandlisa.common.tests.TestCursorTest FAILED

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestDatabaseTest

[junit] Tests run: 1, Failures: 0, Errors: 2, Time elapsed: 0.203 sec

[junit] Test com.jimandlisa.common.tests.TestDatabaseTest FAILED

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.common.tests.TestLoggerTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.AssertTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.063 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtils2Test

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.094 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.218 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ExceptionUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.ReflectionUtilsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.157 sec

[junit] dir attribute ignored if running in the same VM

[junit] Running com.jimandlisa.testutils.tests.TestConstantsTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.062 sec

----- Original Message -----
From: "Peter Reilly" <peter.kitt.reilly@...>
To: <cobertura-devel@...>
Sent: Thursday, September 03, 2009 11:48 PM
Subject: Re: [Cobertura-devel] When junit fork is set to "no",reports
show zero coverage


Try forkmode = once.
With fork=no, the jvm does not exit n

On Sun, Aug 30, 2009 at 6:45 AM, Jim Showalter<jim@...>
wrote:

> The FAQ says:
>
> "When I generate coverage reports, why do they always show 0%
> coverage
> everywhere?
>
> Cobertura is probably using the wrong .ser file when generating the
> reports. When you instrument your classes, Cobertura generates a
> .ser
> file containing basic information about each class. As your tests
> run,
> Cobertura adds additional information to this same data file. If the
> instrumented classes can not find the data file when running then
> they
> will create a new one. It is important that you use the same
> cobertura.ser file when instrumenting, running, and generating
> reports.
>
> The best way to do this is to specify the location of the data file
> when running your tests. You should pass
> the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
> sysproperty to the JUnit task."
>
> I have tried to do that in the ant script:
>
> <target name="test" depends="instrument">
> <junit fork="no" printsummary="yes"
> failureProperty="test.failed">
> <sysproperty key="net.sourceforge.cobertura.datafile"
> value="${basedir}/cobertura.ser"/>
> <classpath>
> <pathelement path="${instrumented.dir}"/>
> <pathelement path="${target.dir}"/>
> <path refid="executing.classpath"/>
> </classpath>
> <formatter type="xml"/>
> <test name="${testcase}" todir="${reports.xml.dir}"
> if="testcase"/>
> <batchtest todir="${reports.xml.dir}" unless="testcase">
> <fileset dir="${test.dir}">
> <include name="**/testutils/tests/*Test.java"/>
> </fileset>
> </batchtest>
> <assertions>
> <enable/>
> </assertions>
> </junit>
> <junitreport todir="${reports.xml.dir}">
> <fileset dir="${reports.xml.dir}">
> <include name="TEST-*.xml"/>
> </fileset>
> <report format="frames" todir="${reports.html.dir}"/>
> </junitreport>
> </target>
>
> But it seems to have no effect. The coverage reports are still
> empty.
>
> What is the trick to getting this to work?
>
> ----- Original Message -----
> From: "Jim Showalter" <jim@...>
> To: <cobertura-devel@...>
> Sent: Saturday, August 29, 2009 9:18 PM
> Subject: [Cobertura-devel] When junit fork is set to "no",reports
> show
> zero coverage
>
>
>>I can't run the tests in separate VMs, because they need to share a
>> static singleton.
>>
>> I changed the ant script to specify fork="no", and removed the
>> dir="${basedir}" because now that's ignored, but now when the tests
>> run they produce JUnit output, but the coverage reports show zero
>> coverage.
>>
>> What's the trick for setting fork="no" but still getting coverage
>> reports?
>>
>> ---------------------------------
>>
>> Jim Showalter
>> http://jimshowalter.blogspot.com
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports
>> 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment -
>> and
>> focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Cobertura-devel mailing list
>> Cobertura-devel@...
>> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: When junit fork is set to "no", reports show zero coverage

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I wound up implementing it with a file after all, so running without
forking is a non-issue for me now.

----- Original Message -----
From: "Jim Showalter" <jim@...>
To: "John W. Lewis" <JohnW.Lewis@...>; "Peter Reilly"
<peter.kitt.reilly@...>; <cobertura-devel@...>
Sent: Friday, September 04, 2009 10:28 AM
Subject: Re: [Cobertura-devel] When junit fork is set to "no", reports
show zero coverage


> Thank you for your response!
>
> Let me describe the use case so you see why I have to run all of the
> tests in one VM.
>
> I'm writing a utility that tests that every error code defined by an
> exception has been seen in a throw.
>
> The API is below.
>
> public final class ErrorCodeUtils
> {
>    /**
>     * Parameterized constructor.
>     * @param exceptionDefiningErrorCodes Class of the exception
> being
> tested.
>     * @param testClasses Classes testing the exception.
>     * @param getErrorCodeMethodName Name of method that returns
> error
> code. Method must have
>     * an int return type, and no parameters.
>     * @throws RuntimeException Problem encountered using reflection
> to get method or error codes.
>     * @throws IllegalArgumentException Exception class does not
> define a method with the
>     * specified name, or defines a method with the specified name,
> but with parameters and/or
>     * a non-int return type; or defines a public field that is not
> an
> int.
>     * @throws IllegalStateException Duplicate error code defined by
> exception being tested.
>     */
>    public ErrorCodeUtils(
>        final Class<? extends Throwable> exceptionDefiningErrorCodes,
>        final Class<?>[] testClasses,
>        final String getErrorCodeMethodName)...
>
>    /**
>     * Reports that a test has finished.
>     * @throws IllegalArgumentException Calling class is not one of
> the test classes.
>     * @throws IllegalStateException Test class has already reported
> finishing, or
>     * this was the last test to finish and there is an untested
> error
> code.
>     * @throws RuntimeException Problem encountered getting finishing
> class, or using
>     * reflection to get error code.
>     */
>    public final synchronized void reportTestFinish()...
>
>    /**
>     * Determines whether specified exception matches expected type
> and has expected error code
>     * and message, or has root cause that matches expected type and
> has expected error code
>     * and message.
>     * @param e Exception.
>     * @param expectedErrorCode Expected error code.
>     * @param matchMessage Part or whole of expected exception
> message, or null if there is no
>     * message or there is a message but it should be ignored.
>     * @throws IllegalArgumentException Error code is undefined.
>     * @throws RuntimeException Exception is null, or exception is
> not
> null but exception or
>     * root cause of exception doesn't match expected type, or
> matches
> expected type but does
>     * not have expected error code, or has expected error code but
> match message is not null
>     * and does not match exception message.
>     */
>    public final void assertIsExpectedException(
>        final Throwable e,
>        final int expectedErrorCode,
>        final String matchMessage) throws RuntimeException..
>
>    /**
>     * Executes constructor for specified class and verifies that it
> throws expected exception type
>     * with expected error code.
>     * @param classToConstruct Class to construct.
>     * @param expectedErrorCode Expected error code.
>     * @param matchMessage Part or whole of expected exception
> message, or null if there is no message
>     * or there is a message but it should be ignored.
>     * @param parameters Parameters to constructor as ordered list of
> type and object pairs, where the
>     * type is the type of the parameter and the object is the value
> of the argument to the parameter.
>     * @throws IllegalArgumentException Error code is undefined.
>     * @throws RuntimeException Exception is not thrown, or exception
> is thrown but exception or root
>     * cause of exception doesn't match expected type, or matches
> expected type but does not have expected
>     * error code, or has expected error code but match message is
> not
> null and does not match exception
>     * message.
>     * <br>
>     * Note: If the Class/Object parameter pairs are invalid,
> InvalidArgumentException will be thrown
>     * by the reflected call, which may or may not match the expected
> exception; if it does match the
>     * expected exception, the assert will pass, but it will be a
> false negative--therefore, care must
>     * be taken to supply valid parameter pairs.
>     */
>    public final void assertThrowsExpectedException(
>        final Class<?> classToConstruct,
>        final int expectedErrorCode, final String matchMessage,
>        final Object... parameters) throws RuntimeException...
>
>    /**
>     * Executes specified static method and verifies that it throws
> expected exception type with
>     * expected error code.
>     * @param classToInvoke Class to invoke static method on.
>     * @param methodName Name of static method to invoke.
>     * @param expectedErrorCode Expected error code.
>     * @param matchMessage Part or whole of expected exception
> message, or null if there is no message
>     * or there is a message but it should be ignored.
>     * @param parameters Parameters to static method as ordered list
> of type and object pairs, where the
>     * type is the type of the parameter and the object is the value
> of the argument to the parameter.
>     * @throws IllegalArgumentException Error code is undefined.
>     * @throws RuntimeException Exception is not thrown, or exception
> is thrown but exception or root
>     * cause of exception doesn't match expected type, or matches
> expected type but does not have expected
>     * error code, or has expected error code but match message is
> not
> null and does not match exception
>     * message.
>     * <br>
>     * Note: If the Class/Object parameter pairs are invalid,
> InvalidArgumentException will be thrown
>     * by the reflected call, which may or may not match the expected
> exception; if it does match the
>     * expected exception, the assert will pass, but it will be a
> false negative--therefore, care must
>     * be taken to supply valid parameter pairs.
>     */
>    public final void assertThrowsExpectedException(
>        final Class<?> classToInvoke, final String methodName,
>        final int expectedErrorCode, final String matchMessage,
>        final Object... parameters) throws RuntimeException...
>
>    /**
>     * Executes specified method and verifies that it throws expected
> exception type with expected
>     * error code.
>     * @param target Object to invoke method on.
>     * @param methodName Name of method to invoke.
>     * @param expectedErrorCode Expected error code.
>     * @param matchMessage Part or whole of expected exception
> message, or null if there is no message
>     * or there is a message but it should be ignored.
>     * @param parameters Parameters to method as ordered list of type
> and object pairs, where the
>     * type is the type of the parameter and the object is the value
> of the argument to the parameter.
>     * @throws IllegalArgumentException Error code is undefined.
>     * @throws RuntimeException Exception is not thrown, or exception
> is thrown but exception or root
>     * cause of exception doesn't match expected type, or matches
> expected type but does not have expected
>     * error code, or has expected error code but match message is
> not
> null and does not match exception
>     * message.
>     * <br>
>     * Note: If the Class/Object parameter pairs are invalid,
> InvalidArgumentException will be thrown
>     * by the reflected call, which may or may not match the expected
> exception; if it does match the
>     * expected exception, the assert will pass, but it will be a
> false negative--therefore, care must
>     * be taken to supply valid parameter pairs.
>     */
>    public final void assertThrowsExpectedException(
>        final Object target, final String methodName,
>        final int expectedErrorCode, final String matchMessage,
>        final Object... parameters) throws RuntimeException...
> }
>
> To use it, a programmer defines a utility class and calls it from
> their test:
>
> package com.example;
>
> public class ExampleException extends RuntimeException
> {
>    private int mErrorCode;
>
>    ExampleException(String message, int errorCode, Throwable e)
>    {
>        super(message, e);
>
>        mErrorCode = errorCode;
>    }
>
>    public static int ZeroLengthString = 0;
>
>    public int getErrorCode()
>    {
>        return mErrorCode;
>    }
> }
>
> package com.example;
>
> public class Example
> {
>    private int count(String string)
>    {
>        // Deliberately not testing for null first so we can show how
> to test for
>        // an exception other than ExampleException.
>
>        if ("".compareTo(string) == 0)
>        {
>            throw new ExampleException("Zero-length string",
> ExampleException.ZeroLengthString, null);
>        }
>
>        return string.length();
>    }
> }
>
> package com.example;
>
> import com.jimandlisa.testutils.ErrorCodeUtils;
>
> public class ExampleErrorCodeUtils
> {
>    private static ErrorCodeUtils sErrorCodeUtils = null;
>
>    static synchronized ErrorCodeUtils getErrorCodeUtils()
>    {
>        if (sErrorCodeUtils == null)
>        {
>            sErrorCodeUtils =
>                new ErrorCodeUtils(
>                    ExampleException.class, new
> Class<?>[]{ExampleTest.class}, "getErrorCode");
>        }
>
>        return sErrorCodeUtils;
>    }
>
>    public static void reportTestFinish()
>    {
>        getErrorCodeUtils().reportTestFinish();
>    }
> }
>
> package com.example;
>
> import org.junit.AfterClass;
> import org.junit.Test;
>
> import com.jimandlisa.testutils.Assert;
> import com.jimandlisa.testutils.ExceptionUtils;
> import com.jimandlisa.testutils.ReflectionUtils;
>
> public class ExampleTest
> {
>    @Test
>    public void testExample()
>    {
>        Example example = new Example();
>
>
> ExampleErrorCodeUtils.getErrorCodeUtils().assertThrowsExpectedException(
>            example, "count",
>            ExampleException.ZeroLengthString, "Zero-length string",
>            String.class, "");
>    }
>
>    @AfterClass
>    public static void finish()
>    {
>        ExampleErrorCodeUtils.reportTestFinish();
>    }
> }
>
> Because the error-code util that keeps track of the calls is a
> static
> singleton per VM, all the tests have to run in one VM. Otherwise,
> when
> each test finishes and calls finish, the singleton in that test's VM
> only sees that test finish. It needs to see all of the tests finish.
>
> I can change it to write the test-finished statuses to a file, but
> then I have to deal with file lock synchronization, etc.
>
> ----- Original Message -----
> From: "John W. Lewis" <JohnW.Lewis@...>
> To: "Jim Showalter" <jim@...>; "Peter Reilly"
> <peter.kitt.reilly@...>;
> <cobertura-devel@...>
> Sent: Friday, September 04, 2009 6:02 AM
> Subject: RE: [Cobertura-devel] When junit fork is set to
> "no",reports
> show zero coverage
>
>
>
> Hi Jim,
>
> Thanks for your blog post!
>
> Peter was suggesting you use forkmode which only makes sense if you
> set fork to yes.
>
> But, you are trying to set fork to no.   That is something no
> Cobertura user has needed to do so far.
>
> I want to put some thought into your question, but at the moment I
> am
> trying to get out a new release of Cobertura that has the latest
> Javancss in it.   I think this will probably solve your second
> problem.
>
> I'll have to get back with you after I have tried out the Cobertura
> release candidate on the test system I maintain.   Hopefully some
> time
> next week...
>
> John
>
> -----Original Message-----
> From: Jim Showalter [mailto:jim@...]
> Sent: Friday, September 04, 2009 3:08 AM
> To: Peter Reilly; cobertura-devel@...
> Subject: Re: [Cobertura-devel] When junit fork is set to "no",
> reports
> show zero coverage
>
> Thank you very much for responding!
>
> I changed fork to once and it still reports zero coverage.
>
> If I change fork to yes, it reports near 100% coverage, except for
> one
> line, which requires that all tests run in the same VM in order to
> be
> covered.
>
> So I'm still stuck.
>
> The problem, I think, is that when I change fork to once, or to no,
> then I see these warnings in the output about the dir attribute, but
> I
> don't know how to set the dir per the FAQ:
>
> "The best way to do this is to specify the location of the data file
> when running your tests. You should pass
> the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
> sysproperty to the JUnit task. "
>
> What would be really helpful is an example of an ant script that
> sets
> the dir.
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.common.tests.AbstractDatabaseTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.406
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.common.tests.DatabaseExceptionTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.203
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.common.tests.LoggerTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.047
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.common.tests.SqlUtilsTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.015
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.common.tests.TestCursorTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.75 sec
>
> [junit] Test com.jimandlisa.common.tests.TestCursorTest FAILED
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.common.tests.TestDatabaseTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 2, Time elapsed: 0.203
> sec
>
> [junit] Test com.jimandlisa.common.tests.TestDatabaseTest FAILED
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.common.tests.TestLoggerTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.testutils.tests.AssertTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.063
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtils2Test
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.094
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.testutils.tests.ErrorCodeUtilsTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.218
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.testutils.tests.ExceptionUtilsTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.testutils.tests.ReflectionUtilsTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.157
> sec
>
> [junit] dir attribute ignored if running in the same VM
>
> [junit] Running com.jimandlisa.testutils.tests.TestConstantsTest
>
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.062
> sec
>
> ----- Original Message -----
> From: "Peter Reilly" <peter.kitt.reilly@...>
> To: <cobertura-devel@...>
> Sent: Thursday, September 03, 2009 11:48 PM
> Subject: Re: [Cobertura-devel] When junit fork is set to
> "no",reports
> show zero coverage
>
>
> Try forkmode = once.
> With fork=no, the jvm does not exit n
>
> On Sun, Aug 30, 2009 at 6:45 AM, Jim Showalter<jim@...>
> wrote:
>> The FAQ says:
>>
>> "When I generate coverage reports, why do they always show 0%
>> coverage
>> everywhere?
>>
>> Cobertura is probably using the wrong .ser file when generating the
>> reports. When you instrument your classes, Cobertura generates a
>> .ser
>> file containing basic information about each class. As your tests
>> run,
>> Cobertura adds additional information to this same data file. If
>> the
>> instrumented classes can not find the data file when running then
>> they
>> will create a new one. It is important that you use the same
>> cobertura.ser file when instrumenting, running, and generating
>> reports.
>>
>> The best way to do this is to specify the location of the data file
>> when running your tests. You should pass
>> the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser
>> sysproperty to the JUnit task."
>>
>> I have tried to do that in the ant script:
>>
>> <target name="test" depends="instrument">
>> <junit fork="no" printsummary="yes"
>> failureProperty="test.failed">
>> <sysproperty key="net.sourceforge.cobertura.datafile"
>> value="${basedir}/cobertura.ser"/>
>> <classpath>
>> <pathelement path="${instrumented.dir}"/>
>> <pathelement path="${target.dir}"/>
>> <path refid="executing.classpath"/>
>> </classpath>
>> <formatter type="xml"/>
>> <test name="${testcase}" todir="${reports.xml.dir}"
>> if="testcase"/>
>> <batchtest todir="${reports.xml.dir}" unless="testcase">
>> <fileset dir="${test.dir}">
>> <include name="**/testutils/tests/*Test.java"/>
>> </fileset>
>> </batchtest>
>> <assertions>
>> <enable/>
>> </assertions>
>> </junit>
>> <junitreport todir="${reports.xml.dir}">
>> <fileset dir="${reports.xml.dir}">
>> <include name="TEST-*.xml"/>
>> </fileset>
>> <report format="frames" todir="${reports.html.dir}"/>
>> </junitreport>
>> </target>
>>
>> But it seems to have no effect. The coverage reports are still
>> empty.
>>
>> What is the trick to getting this to work?
>>
>> ----- Original Message -----
>> From: "Jim Showalter" <jim@...>
>> To: <cobertura-devel@...>
>> Sent: Saturday, August 29, 2009 9:18 PM
>> Subject: [Cobertura-devel] When junit fork is set to "no",reports
>> show
>> zero coverage
>>
>>
>>>I can't run the tests in separate VMs, because they need to share a
>>> static singleton.
>>>
>>> I changed the ant script to specify fork="no", and removed the
>>> dir="${basedir}" because now that's ignored, but now when the
>>> tests
>>> run they produce JUnit output, but the coverage reports show zero
>>> coverage.
>>>
>>> What's the trick for setting fork="no" but still getting coverage
>>> reports?
>>>
>>> ---------------------------------
>>>
>>> Jim Showalter
>>> http://jimshowalter.blogspot.com
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Let Crystal Reports handle the reporting - Free Crystal Reports
>>> 2008
>>> 30-Day
>>> trial. Simplify your report design, integration and deployment -
>>> and
>>> focus on
>>> what you do best, core application coding. Discover what's new
>>> with
>>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>>> _______________________________________________
>>> Cobertura-devel mailing list
>>> Cobertura-devel@...
>>> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports
>> 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment -
>> and
>> focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Cobertura-devel mailing list
>> Cobertura-devel@...
>> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Some open-source testing utilities you may find useful

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://jimshowalter.blogspot.com/2009/09/test-utils-are-now-open-source.html

---------------------------------
Jim Showalter
http://jimshowalter.blogspot.com 


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel