MoreUnit

Thursday, 23 January 2014, 21:27

Tags: Eclipse MoreUnit TDD

MoreUnit is a great Eclipse plugin which makes writing and maintaining tests easier. Rename classes or methods and MoreUnit will rename the corresponding test code too. Move classes and MoreUnit will move the corresponding test classes.

MoreUnit also provides several shortcuts to help you create and run tests easily.

  • Ctrl + J: Jump to the test class or method you are editing. When no test class exists MoreUnit proposes to create a new test class.
  • Ctrl + R: Run the tests of the class that is opened.
  • Ctrl + U: Generate a test method for the method you are editing. When no test class exists MoreUnit first proposes to create a new test class.

When installing MoreUnit you have to configure several things. (Window -> Preferences -> MoreUnit -> Java)

  • Define the source folder where the test classes will be located: src/test/java
  • Select the correct JUnit version: JUnit 4
  • Choose the naming pattern: ${srcFile}*Test
  • Do not use the test prefix for test mehtods. The @Test annotation of JUnit 4 will make clear that it is a test.
  • Use an empty method content when creating a new test.
  • Do not add a pre- or suffix to the test package, this way the test class will be in the same package as the class under test. I also do not automatically use a specific superclass.
  • Enable extended search for test methods. By enabling this option MoreUnit will search the body of a test method to try and figure out which method is under test. This is useful when your test methods have other names than the method under test.