Skip to content

Instantly share code, notes, and snippets.

@prule
Created July 11, 2019 12:00
Show Gist options
  • Save prule/194b946504f2b88624cfd659d4fc1a66 to your computer and use it in GitHub Desktop.
Save prule/194b946504f2b88624cfd659d4fc1a66 to your computer and use it in GitHub Desktop.
Intellij IDEA Template for a JUnit 5 / Spring boot integration test
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
// @TestPropertySource(locations = "/application-xxx.properties")
// @ActiveProfiles({"simulator-s3"})
public class ${NAME} {
// @Value("${}") private String value;
@BeforeEach
public void before() {
}
@AfterEach
public void after() {
}
@Test
public void test() throws Exception {
// setup
// execute
// verify
// assertThat(actual).isEqualTo(expected);
}
}
@prule
Copy link
Author

prule commented Jul 11, 2019

Add this template by going to Preferences > Editor > File and Code Templates, click the + sign - Name your template something like "Integration Test" and paste in the template content above.

You can then create a class using this template by selecting some in a java source directory in the Project pane and pressing Command-N (on MacOS) - your template will be listed (and you can filter the list if you start typing)

To support the spring boot tests you'll also need to set up a spring boot application by doing something like the following:

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * A spring boot application to support the spring enabled tests
 */
@SpringBootApplication
public class TestApplication {
}

Screen Shot 2019-07-11 at 10 08 16 pm

Screen Shot 2019-07-11 at 10 09 37 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment