Bug 133777 - JUnit swallows failure text
Summary: JUnit swallows failure text
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2006-03-29 01:13 EST by Jens Elkner CLA
Modified: 2009-08-30 02:06 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Elkner CLA 2006-03-29 01:13:29 EST
Actually it is very hard to analyse failures within eclipse, since eclipse swallows error messages.

E.g.:

Iterator i = eset.iterator(); // ENumSet
while (i.hasNext()) {
	Enum e = (Enum) i.next();
	String val = props.getProperty(e.name());
	assertNotNull(clazz.getSimpleName() + "#" + e.name() 
		+ " not found ", val);
	assertTrue("Ordinal value differs for " 
		+ clazz.getSimpleName() + "#" + e.name() + ": "
		+ e.ordinal() + " != " + val,
		e.ordinal() == Integer.parseInt(val, 10));
}

In this case, it is obvious, where the test fails, but not for which values since error messages are swallowed. This drives me crazy!

Why is it not possible to write those messages to the console ?
Comment 1 Wayne Beaton CLA 2006-03-29 08:52:40 EST
Why not use the text TestRunner?
Comment 2 Jens Elkner CLA 2006-03-29 09:49:33 EST
Elobarate please!
Comment 3 Wayne Beaton CLA 2006-03-29 10:03:04 EST
Add a main method somewhere that does this:

	public static void main(String[] args) {
		junit.textui.TestRunner.run(SomeTests.class);
	}

Run your tests in the GUI to get immediate feedback and the comforting green bar. Run them using the text TestRunner to get output in the console that you can save somewhere. You can also invoke the test TestRunner from Ant (to capture your test output during a build, for example).
Comment 4 Jens Elkner CLA 2006-03-29 10:29:26 EST
Ahh - I see, what you mean. Actually the projects I'm working with have an appropriate ant task and the test classes have the main method. But that's not the point. 

At least my point is: When I touch a junit test within the IDE, I have usually a problem, which needs to be fixed. So I usually need to run a single testXXX() method. (Of course its also quite annoying, that in this case the Hierarchy view removes the "class test tree" and just displays the single test method, only). Of course, I may run the complete test, but how long should I wait, until the testMethod() in question gets executed? In some cases this would mean hours, which is of course more than inefficient. OK, one could put each testMethod in a separate TestClass, but how efficient/cumbersome would this be?
Comment 5 Wayne Beaton CLA 2006-03-29 10:47:38 EST
I'm not sure if I completely understand your issue. But it seems to me that your tests are too coarse-grained. Ideally, you should have multiple test classes that each test some small piece of your functionality. Ideally, each of these test classes should run really fast all by itself. Again ideally, tests are aggregated using suites that you can use to test increasingly larger bits of your functionality.

That said, you can invoke a single test method by selecting the method in the Package Explorer and select "Run as... > JUnit Test" from the context menu.

If you want to run just a single test method using the text TestRunner, you can provide the method name in your test constructor.

	public static void main(String[] args) {
		TestRunner.run(new SomeTests("testSomethingElse"));
	}

You can also build a suite() method that creates a Test containing multiple method invocations.
Comment 6 Jens Elkner CLA 2006-03-29 14:04:49 EST
Sorry Wayne, but you are still missing the point. Just download hibernate and run some test, e.g. test/org/hibernate/test/legacy/FumTest.java . Or download other OpenSource software and run some tests. You'll probably get a little clue, what I'm talking about.

I guess, you have no desire, to start teaching people, how to write their tests or even telling them, that they do the wrong thing (and haven't that desire, too ;-)). And yes, even testing a small piece of functionality may impose a lot of tests, which should be of course grouped together. 

Anyway, if course-grained or not, IDE should help to improve the efficiency of a developer, otherwise one does not need that waste ...
Comment 7 Wayne Beaton CLA 2006-03-29 14:45:40 EST
(In reply to comment #6)
> Sorry Wayne, but you are still missing the point. Just download hibernate and
> run some test, e.g. test/org/hibernate/test/legacy/FumTest.java . Or download
> other OpenSource software and run some tests. You'll probably get a little
> clue, what I'm talking about.

I don't have that kind of time right now. But maybe for fun later :-) If the point is that these tests take a long time to run, then I understand (at least this much) already.

> I guess, you have no desire, to start teaching people, how to write their tests
> or even telling them, that they do the wrong thing (and haven't that desire,
> too ;-)). And yes, even testing a small piece of functionality may impose a lot
> of tests, which should be of course grouped together. 

Actually, I have no problem teaching people how to write tests and relish the opportunity. I may have to look harder at these Hibernate tests...
 
> Anyway, if course-grained or not, IDE should help to improve the efficiency of
> a developer, otherwise one does not need that waste ...

Agreed. But I think Eclipse already does this. To start, if I use the test runner built into Eclipse, I see the failure messages and can even view the stack trace for the failure. If my test code throws an exception, I can also see the stack trace for the exception. I can also double-click on the failure which takes me right to the method where I can insert a breakpoint. I can then rerun just the one method that caused the failure. Assuming my tests cases don't depend on each other (which is a no-no) this should work splendly.

I can also select a single method from a test class and run it all by itself in the test runner.

I can also do most of this using just the standard JUnit test runner.

Is the problem that you can't easily identify the method that you want/need to test in isolation?

Maybe you can try restating the original problem; I (apparently) can't seem to  get it through my thick skull... ;-)
Comment 8 Karice McIntyre CLA 2006-04-18 18:19:23 EDT
Jens, I think you need to explain how you are running your JUnit tests in Eclipse.  The standard provided means of running JUnit tests that Wayne is describing will show you the message associated with the failed assertion (in the JUnit view) if it fails.  Are you using Run As > JUnit Test or Run As > JUnit Plugin test to run your JUnit tests?
Comment 9 Jens Elkner CLA 2006-04-18 21:15:18 EDT
Yes. And than via the favorite toolbar button or context menu on the testMethod.
E.g window-shot http://linofee.org/~jel/develop/eclipse/junit.jpg

As you can see, I'm started to manually check and "real" log the problem if any and use assert just to let the test fail. Yes, its a little bit stupid, code cluttering ... and yes, already got the question: why do you need junit, if you do the most/main stuff manually anyway ...
Comment 10 Karice McIntyre CLA 2006-04-19 13:46:46 EDT
Not sure if this is a JUnit UI issue (i.e. in Eclipse) or a JUnit issue.  Moving to JDT UI for comment.
Comment 11 Markus Keller CLA 2006-04-20 12:07:41 EDT
I don't quite understand what you want.

(A) Are you satisfied with plain JUnit (i.e. the main from comment 3), but you don't like the way test results are shown in the Eclipse JUnit view?

or

(B) Do you think it's wrong that JUnit stops execution of a test method when the first assertion fails? (If this is the case, then it's a JUnit problem, not an Eclipse one.)

or

(C) Something else?

Please try to describe your wish in JUnit-style 'expected' vs. 'was', giving example output for both what you find today and what you expect.
Comment 12 Jens Elkner CLA 2006-04-20 22:23:20 EDT
(A)
Comment 13 Markus Keller CLA 2006-04-21 09:28:47 EDT
Again: Please try to describe your wish in JUnit-style 'expected' vs. 'was', giving example output for both what you find today and what you expect.

From comment 0, it's not obvious what's wrong, and the link in comment 9 does not work for me.
Comment 14 Markus Keller CLA 2006-06-07 12:14:56 EDT
Awaiting a more precise description. The AssertionFailedError's message is not swallowed. It is shown in JUnit's Failure Trace pane.
Comment 15 Denis Roy CLA 2009-08-30 02:06:16 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.