Junit 使用方法
来源:互联网 发布:bp神经网络 预测 java 编辑:程序博客网 时间:2024/06/06 20:42
1、pom.xml中引入需要的jar
注:建议spring-Test.jar在pom.xml 文末引入,我在最前面引入报错,说是缺少jar,这点事需要注意的
<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version> 3.2.4.RELEASE </version> <scope>provided</scope> </dependency>
2、写Junit基类,别的类通过继承此类调用
package com.loan.util;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)//注入bean@ContextConfiguration("classpath:/application-context.xml")public class BaseJunit {}3、书写测试类
package com.loan.back.controller;import javax.annotation.Resource;import org.junit.Test;import com.loan.security.service.ResourceService;import com.loan.util.BaseJunit;public class JunitTest extends BaseJunit{@Resourceprivate ResourceService resourceService;@Testpublic void load(){System.out.println(resourceService.load((long)8).toString());}}
4、运行方式
鼠标放置到需运行的方法(load)上,然后右键run as -> JUnit Test即可
Controller测试:
@Controller@RequestMapping("/admin/resource")public class ResourceController extends BaseJunit{@javax.annotation.Resourceprivate ResourceService resourceService;@javax.annotation.Resourceprivate RoleResourceService roleResourceService;@Test@RequiresPermissions("resource:view")@RequestMapping(value="/list", method = RequestMethod.GET)public void load(){System.out.println(resourceService.load((long)8).getPic());}}
至此,成功!
阅读全文
0 0
- JUnit使用方法
- JUnit使用方法
- Junit 使用方法
- JUnit 简明使用方法
- junit 4 使用方法
- JUnit的使用方法介绍
- Junit的使用方法
- Junit简单使用方法
- junit的配置和使用方法
- Junit-断言(Assert)使用方法
- junit的Rule使用方法介绍
- Junit参数化测试的使用方法
- jUnit单元测试简单的安装和基本的使用方法
- JUNIT
- junit
- Junit
- JUnit
- JUnit
- 使用Spring Cloud和Docker构建微服务架构
- 75. Sort Colors
- 写给刚进大学接触ACM的同学
- linux命令之pwd
- 获取文件名和路径,方便调用程序
- Junit 使用方法
- Anaconda 仓库的镜像
- CSDN 如何转载博客
- 爬虫任务设计要有父子概念,即抓取网站和抓取任务的概念
- C# 基本语法
- C 去除字符串结尾换行符(去除字符串最后一个字符)
- Error:Execution failed for task ':app:clean'
- web前端CSS2学习2017.6.17
- hadoop命令