jq實現加減功能
阿新 • • 發佈:2022-03-05
一、整合步驟
① 匯入spring整合Junit的座標
② 使用@Runwith註解替換原來的執行期
③ 使用@ContextConfiguration指定配置檔案或配置類
④ 使用@Autowired注入需要測試的物件
⑤ 建立測試方法進行測試
1.匯入座標
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.0.2.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
例項
@RunWith(SpringJUnit4ClassRunner.class)
// 載入 spring 核心配置檔案
//@ContextConfiguration(value = {"classpath:applicationContext.xml"})
@ContextConfiguration(classes = {SpringConfiguration.class})
public class SpringJunitTest {
@Autowired
private UserService userService;
@Test
public void testUserService(){
userService.save();
}
}