How can I have newly created JUnit tests based on a template?

Ctrl-Shift-T creates me a new test - fantastic.

But - how can I change how that new test is created? In my newly created JUnit 4 tests, I'd really like to have imports for org.junit.Assert.*. I'd also really like to have imports for the Hamcrest matcher packages.

Is there any way of doing this?




Ah - to answer my own question, it looks like you can't: it's issue

Oh well.


It seems that IDEA uses the 'new class' template for generated tests.  I thought adding

#if ($NAME.endsWith("Test"))
import static org.junit.Assert.*;

to the template might work... It adds the extra import to new classes that end in "Test".


I do this using a file template below is my "Basic JUnit4 Test" template:

#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class ${NAME} {
    public static void beforeClass() throws Exception {
    public void before() {
    public void after() {
    public void basicTest() throws Exception {


Please sign in to leave a comment.