一、配置 Pom 坐标
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.0.13.RELEASE</version> <scope>compile</scope> </dependency>
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency>
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.0.13.RELEASE</version> </dependency> </dependencies>
|
二、 编写测试类
/test/java/cn/pangcy/service/UserServiceTest
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class) public class UserServiceTest {
@Autowired private UserService userService;
@Test public void testFindUser(){ System.out.println("Test Find User Begin"); System.out.println(userService.findUser()); System.out.println("Test Find User End"); } }
|