Created
July 11, 2019 11:59
-
-
Save prule/c4255e6fc6b34ab02289c65bf135486f to your computer and use it in GitHub Desktop.
Template for a JUnit 5 / Spring boot integration test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") or @ActiveProfiles({"xxx"}) | |
public class Junit5SpringBootTestTemplate { | |
// @Value("${xxx}") private String value; | |
@BeforeEach | |
public void before() { | |
} | |
@AfterEach | |
public void after() { | |
} | |
@Test | |
public void test() throws Exception { | |
// setup | |
// execute | |
// verify | |
// assertThat(actual).isEqualTo(expected); | |
} | |
} | |
// and also define a spring boot application to support the test | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
/** | |
* A spring boot application to support the spring enabled tests | |
*/ | |
@SpringBootApplication | |
public class TestApplication { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment