Spring整合JUnit
-
导入坐标
-
<!--spring整合junit坐标--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.2.10.RELEASE</version> </dependency> <!--junit坐标--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
-
-
在测试类中添加注解
-
@RunWith(SpringJUnit4ClassRunner.class)//设置类运行器 @ContextConfiguration(classes = SpringConfig.class)//设置Spring的配置类 public class AccountServiceTest { @Autowired private AccountService accountService;//自动装配service对象进行测试 @Test public void TestFindById(){ System.out.println(accountService.findById(1)); } @Test public void TestSelectAll(){ System.out.println(accountService.findAll()); } }
-