Bug 7980 - JUnit spawned thread spits output to STDOUT, not formatter destination
Summary: JUnit spawned thread spits output to STDOUT, not formatter destination
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.4.1
Hardware: PC other
: P3 normal (vote)
Target Milestone: 1.6
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-11 19:28 UTC by Russ Milliken
Modified: 2004-11-16 19:05 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Russ Milliken 2002-04-11 19:28:26 UTC
Consider the following buildfile snippet:

<junit>
    <batchtest todir="${project.build.test.reports}" fork="no">
        <formatter type="plain" usefile="yes" />
        <fileset dir="${project.build.classes}">
            <include name="**/Test*" />
        </fileset>
    </batchtest>
</junit>

This buildfile snippet runs all classes which begin with "Test" (in our 
project, all such classes inherit from JUnit's "TestCase" class) in JUnit.

Some of our "public void test*()" methods in these classes spawn Threads; some 
of these spawned Threads print output to System.out.  This output actually goes 
to console, and not to the <formatter>'s destination as the documentation 
states: "Output will always be sent to a file unless you set the usefile 
attribute to false".

This also occurs in the 1.5 alpha (nightly) build on 04-11-02.
Comment 1 Conor MacNeill 2002-04-12 01:06:17 UTC

*** This bug has been marked as a duplicate of 5377 ***
Comment 2 Stefan Bodewig 2002-04-16 15:31:27 UTC
Actually this is not really a duplicate of bug 5377.

5377 was concerned with output in the fork="true" case, which work now - with
or without spawned threads.

This one is a lot more difficult to tackle (to be honest, I don't know how).
What we have here is that a test case spawns a thread in Ant's VM.  

Ant's output handling system doesn't know about the new thread and therefore
will not pass the output to the junit task but send it to the logging system
directly.  As the <junit> task doesn'r receive the output, it cannot
suppress/swallow it.

If we simply pass all output to junit (by replacing System.out directly),
junit will receive the output of different tasks when running inside <parallel>
as well and label it as test case output.  Bad.
Comment 3 Conor MacNeill 2003-02-10 12:56:26 UTC
Fixed by using ThreadGroups to track threads back to the owning task. Any chance
you can retry with the code from CVS or the next nightly build?
Comment 4 Russ Milliken 2003-02-10 14:07:41 UTC
I will try to try this from a nightly build, though I may not get to it until 
this coming weekend (2/15-16/03).