Thomas Sundberg

June 1, 2012

Adding a JUnit test template in IntelliJ IDEA

Filed under: Automation, Java, Programming — Tags: , , , — Thomas Sundberg @ 07:33

This post is available at http://www.thinkcode.se/blog/2012/06/01/adding-a-junit-test-template-in-intellij-idea

Advertisements

4 Comments »

  1. Actually, IntelliJ has a template for creating JUnit tests, but it is available as a “File template” and not a “Live template”:

    1. Open your test class
    2. “Right click” and select “Generate…” (or simply press “ctrl” + “n” if you use mac)
    3. Select “Test Method” and implement your test

    To change the template:

    1. Open “Settings”
    2. Select “File Templates”
    3. Select “Code”
    4. Select “JUnit4 Test Method” and do your changes

    Comment by Mattias Severson — June 6, 2012 @ 18:24

    • This was news to me. I will make I try it out to see if does what I want it to do.

      Thanks for telling!
      Thomas

      Comment by Thomas Sundberg — June 7, 2012 @ 19:00

  2. And also, if you are looking at the class you want to test, just press Ctrl-Shift-T (or Cmd-Shift-T) and it will create the test class for you after asking whether you want to use junit 3,4 or testng.

    Comment by Jamie Briant — November 27, 2013 @ 06:25

    • The only issue I have with that is that I must create the class I want to test before I start writing the tests. I prefer to work the other way around, create the test and then see which classes I actually have to implement.

      /Thomas

      Comment by Thomas Sundberg — November 27, 2013 @ 07:24


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: