Software Development

Execute specific unit test in Maven using Eclipse

Okay, your project has hundreds of unit tests but you only need to execute one or perhaps only all tests from a JUnit test file. Maven allows for that and Eclipse makes it more convenient.

[wp_ad_camp_5]

Eclipse JUnit Run Configuration

With Eclipse, you can perform the following:

  1. Run all tests in certain project, package, or source folder
  2. Run all tests in a JUnit file
  3. Run specific test in a JUnit file

All these options are available on the same UI window as shown below. If you are to select option 1 from the above list, choose “Run all tests in the selected project, package or source folder.”

Run Only one Test

The following image shows a JUnit run configuration that executes a test method.

[wp_ad_camp_4]

junit-maven-eclipse-24-3-2016 9-43-17 AM

Run All Tests from a Test class

To run all tests from a test class, choose “all methods” from a list shown when “Search…” is clicked.

junit-maven-eclipse-24-3-2016 9-43-56 AM

Eclipse Maven Build Run Configuration

[wp_ad_camp_3]

Running tests from Maven is a bit different because you need to specify parameters (aka Goals and etc) as you would when running an application from a command-line prompt.

Run Only one Test

junit-maven-eclipse-24-3-2016 9-57-40 AM

 Run All Tests from a Test class

junit-maven-eclipse-24-3-2016 9-57-16 AM

[wp_ad_camp_1]

Download the Maven Project

You may download the Maven project used for this post.

https://www.dropbox.com/s/gf79xfdsom4dmla/turreta.com-onetest.zip?dl=0

You Might Also Like