Skip to content

Commit 582147e

Browse files
authored
Merge pull request eugenp#2957 from asturcon/tutorials/runWithJUnit5
@RunWith in JUnit5
2 parents 7a2d2c5 + efe0655 commit 582147e

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎junit5/pom.xml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
3030
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
3131
<junit4.version>4.12</junit4.version>
32+
<spring.version>5.0.1.RELEASE</spring.version>
3233
</properties>
3334

3435
<build>
@@ -111,6 +112,17 @@
111112
<version>${junit4.version}</version>
112113
<scope>test</scope>
113114
</dependency>
115+
<dependency>
116+
<groupId>org.springframework</groupId>
117+
<artifactId>spring-test</artifactId>
118+
<version>${spring.version}</version>
119+
<scope>test</scope>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.springframework</groupId>
123+
<artifactId>spring-context</artifactId>
124+
<version>${spring.version}</version>
125+
</dependency>
114126

115127
</dependencies>
116128

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.junit5.spring;
2+
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.api.extension.ExtendWith;
7+
import org.springframework.test.context.ContextConfiguration;
8+
import org.springframework.test.context.junit.jupiter.SpringExtension;
9+
10+
import com.baeldung.junit5.Greetings;
11+
12+
@ExtendWith(SpringExtension.class)
13+
@ContextConfiguration(classes = { SpringTestConfiguration.class })
14+
public class GreetingsSpringTest {
15+
16+
@Test
17+
void whenCallingSayHello_thenReturnHello() {
18+
assertTrue("Hello".equals(Greetings.sayHello()));
19+
}
20+
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.junit5.spring;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
5+
@Configuration
6+
public class SpringTestConfiguration {
7+
8+
}

0 commit comments

Comments
 (0)