Eclipse template to insert test methods should-given-when-then

(originally posted on StackOverflow)
I saw a similar version to this one recently while pair programming with a very a good developer and friend, and I think it could be a nice addition to this list.

This template will create a new test method on a class, following the Given – When – Then approach from BDD paradigm on the comments, as a guide for structuring the code. It will start the method name with “should” and let you replace the rest of the dummy method name “CheckThisAndThat” with the best possible description of the test method responsibility. After filling the name, TAB will take you straight to the // Given section so you can start typing your preconditions.

I have it mapped to the three letters “tst”, with description “Test methods should-given-when-then” 😉

I hope you find it as useful as I did when I saw it:

public void should${CheckThisAndThat}() {"Not yet implemented");
    // Given

    // When

    // Then

}${:import(org.junit.Test, org.junit.Assert)}

Leave a Reply

Your email address will not be published. Required fields are marked *