Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spring Boot + JUnit minimal required code
package io.lenar.examples.junitspringboot.tests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = JUnitWithSpringBootTestsContext.class)
public class JUnitWithSpringBootExampleIT {
@Value("${foo}")
private String foo;
@Test
public void twoPlusTwoTest() {
assertEquals(4, 2 + 2);
}
@Test
public void springBootJUnitParameterInjectedTest() {
assertEquals("foofoo", foo);
}
}
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
package io.lenar.examples.junitspringboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JUnitWithSpringBootTestsContext {
public static void main(String[] args) {
SpringApplication.run(JUnitWithSpringBootTestsContext.class, args);
}
}
@LenarBad

This comment has been minimized.

Copy link
Owner Author

@LenarBad LenarBad commented May 11, 2018

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