Bug 479553 - [JUnit] assertions are not enabled by default
Summary: [JUnit] assertions are not enabled by default
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.6 M7   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-12 06:17 EDT by Peter CLA
Modified: 2016-09-09 15:34 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter CLA 2015-10-12 06:17:51 EDT
Analouge to a bug in Netbeans (https://netbeans.org/bugzilla/show_bug.cgi?id=175517) asserations should be activated by default.

So intellij idea enables asserations in junit tests, netbeans does, maven does and many many more. Only eclipse does not.

Step 1
1. Create empty junit test.
2. Insert `assert false;`
3. Execute test.
Expected: Test failure.
Comment 1 Dani Megert CLA 2015-10-28 07:19:21 EDT
Since assertions are off by default we run JUnit with the same default, but you can enable this on the 'JUnit' preference page.
Comment 2 Peter CLA 2015-10-28 08:07:07 EDT
Official documentation (JLS7 in page 378) sais: 
Typically, assertion-checking is enabled during program development and testing, and disabled for deployment, to improve performance.

I do not accpet that Java, Oracle, Maven, IntelliJ, Ant, NetBeans and all the other development tools are wrong.
Comment 3 Stephan Herrmann CLA 2015-10-28 19:40:35 EDT
I think changing the default for JUnit runs makes a lot of sense.
Comment 4 Dani Megert CLA 2015-10-29 07:32:59 EDT
(In reply to Peter from comment #2)
> Official documentation (JLS7 in page 378) sais: 
> Typically, assertion-checking is enabled during program development and
> testing, and disabled for deployment, to improve performance.

Good point.

Default was chosen in bug 45408 comment 27.
Comment 5 Markus Keller CLA 2016-04-21 13:06:42 EDT
Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=8a5afa464b6bab19deb769751f45c21b099dfa8a

Note that the new default only affects new launch configurations.
Comment 6 Till Brychcy CLA 2016-04-21 15:09:29 EDT
I'm getting a test failure now:
TestEnableAssertions.testAssertionsOffByDefault
Looks like this test should be changed...
Comment 7 Stephan Herrmann CLA 2016-04-21 15:10:35 EDT
(In reply to Till Brychcy from comment #6)
> I'm getting a test failure now:
> TestEnableAssertions.testAssertionsOffByDefault
> Looks like this test should be changed...

re-opening
Comment 8 Peter CLA 2016-04-21 15:20:53 EDT
Why did the unit test fail? Did you enabled asserations before unittest? No? They should be activated by default, if they are not enabled by default maybe its a bug in the IDE you use. Oh, here we go, its this bug i guess: https://bugs.eclipse.org/bugs/show_bug.cgi?id=479553

Oh, Déjà vu!
Comment 10 Markus Keller CLA 2016-04-22 07:49:31 EDT
Thanks Noopur.
Comment 11 Peter CLA 2016-09-09 15:34:07 EDT
Thanks Noopur, luckily the test does not use the built-in assert-keyword because there was a bug inside eclipse:

  https://bugs.eclipse.org/bugs/show_bug.cgi?id=479553


:p