A JBoss Project
Red Hat

Working Efficiently with JUnit in Eclipse - Update

posted by Aurélien Pupier on Apr 15, 2016.

eclipse

Comments

I just wanted to add a few updates and my two cents to this old but still useful and accurate blog post (which is a must read of course!). Some elements were already mentioned in comments and I think all of that is worth providing a new detailed article.

Favorites - static import

There were mentions of adding static imports for JUnit Assert methods. I recommend also to add some others for these popular frameworks:

Please check out the below screenshot for what to add to your favorites:

favoritesStaticImport

Improvements for Method Templates

There is no more need to type twice Ctrl+space to have the JUnit 4 Template proposals. Even better, when you start typing "test", the JUnit 4 Template is listed first.

testAutoCompletionJunit4before

Test Failures - How to easily compare results

Did you ever noticed the little icon on top right corner of JUnit view?

compareResult JUnit

Click on it! You will get a nice dialog comparing the actual and expected results:

compareResultDialog JUnit

MoreUnit - Avanced Test Development Toolbox

MoreUnit is a plugin helping you to create and maintain Unit Tests. Some of its nice features are:

  • Wizard to create test stubs, including Mock support

  • Navigate between test class and class under test using Ctrl+J

  • Refactoring: renaming classes/methods also renames the corresponding test code

If you have tests in another projects - for instance you are an Eclipse RCP developer and use fragments for your unit tests - you can specify this folder from the MoreUnit Preferences page.

specificTestFolderMOreUnit

Infinitest - Continuous testing

Infinitest is a useful plugin to respect the Fail fast principle. It continuously executes tests in the background each time you save a file.

statusBarUpdatedOnEverySave Infinitest

If there are test failures:

  • The bottom-left status bar is turning red

  • Problem Markers are created to spot failing tests easily

ProblemMarkers InfiniTest

As some tests might be time consuming or requiring some external configuration or UI interactions, you can filter those by providing a infinitest.filters file at the root of the project. The same file will be used in other supported IDEs by Infinitest.

Eclemma - Spot untested code

After you wrote your tests, I recommend to launch the Eclemma Coverage tests. You can use Alt+Shift+E,T. It will show you a nice overview of possible missing test coverage in your code.

eclemma

Note: Don’t focus too much on the percentage but have a deeper look to uncovered or partially covered lines. Make sure that these lines are not critical ones.

For Eclipse RCP Developer

If you’re an Eclipse RCP developer, I will be happy to see you assisting to presentation at my talk at EclipseCon France (Toulouse, June 7-9). I will talk about possible architectures and available tooling to have fast Unit tests while developing Eclipse plugins. I’m looking forward sharing my experience and continue discussions later on.

And You?

Do you have some other Tips, Tricks and best practice to share?

If you are using a different IDE, do you know about killer features enabling you to efficiently write unit tests but which are missing in Eclipse? Please share them!

Latest posts

JBoss Tools 4.29.1.Final for Eclipse 2023-09

by Stéphane Bouchet on Jun 13, 2024.

JBoss Tools 4.29.0.Final for Eclipse 2023-09

by Stéphane Bouchet on Nov 02, 2023.

JBoss Tools 4.28.0.Final for Eclipse 2023-06

by Stéphane Bouchet on Jul 03, 2023.

JBoss Tools for Eclipse 2023-06M2

by Stéphane Bouchet on Jun 05, 2023.

JBoss Tools 4.27.0.Final for Eclipse 2023-03

by Stéphane Bouchet on Apr 07, 2023.

Looking for older articles ? See the Archived entries.
back to top