Code Generation

Main Feature:

  • Auto generate unit test code in Java, Groovy or Scala
  • Generate Mocks for tested class’s non-primitive fields
  • Support Mockito & PowerMock mock frameworks
  • Support JUnit4, JUnit5, TestNG & Spock unit test frameworks
  • Generate Test methods for each accessible non-private method, excluding setters/getters
  • Generate default input parameters for tested methods
  • Generate test result assertion expression
  • Supported target tested class language: Java , Groovy, Scala.

Test parameters generation

Default values are auto generated for the tested methods parameters. Currently, this behaviour is not configurable. Groovy tests generators are more robust in a sense that map constructors can be used, when applicable, to initialize objects with setters inline. Such matching feature is not supported yet for Java test generators, since assignment to local variables for initialization of test parameters complicates the test generation template. Personally, I would always recommend preferring Groovy over Java when it comes to unit testing. If you haven’t transitioned yet to Groovy as your test code language of choice - now is a good time start :)

Tip: Generated test method call line can get very long depending on the depth level of nested objects passed to the tested method. Set the max line limit in IntelliJ Code Style configuration: Preferences (Ctrl+Shift+S) -> Editor -> Code Style -> Java or Groovy -> set Right margin (columns) and check Ensure right margin is not exceeded. Please note these settings will effect not just the test code generation. Currently its not possible to control the max line length for generated test code only.

Test class mocks generation

Mocks are generated for non primitives/non wrapper types classes. There’s some technical difficulties in identifying which class member dependency should be mocked. Some use cases may be controversial. There’s still some work to be done on this…

Tip: By default, Mockito mocks will not be generated for final types. To turn that option on, as specified in these Mockito instructions, create a file in project resources with the path uri - /mockito-extensions/org.mockito.plugins.MockMaker. The file should contain the line: mock-maker-inline.

TestMe motto and current shortcomings

TestMe IJ Plugin aims at generating as much Unit Test boilerplate as possible. The project still lacks some maturity level. You can further read about those dilemmas in this blog post

Submit a new Future Request on the project forum

Updated: