maven下使用junit对spring进行单元测试_01基本应用
2016-12-06 18:10
555 查看
https://my.oschina.net/dlpinghailinfeng/blog/336694
一、开发环境
maven版本:3.0.5spring版本:spring3.2.3 release
junit版本:4.11
eclipse版本:3.7.2 r2
jdk版本:1.6
二、文件清单
pom.xml
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>1.9.5</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.2.3.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.2.3.RELEASE</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
public class Employee { private Integer age; private String name; public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Employee(Integer age,String name){ this.age=age; this.name=name; } @Override public String toString(){ return "Employee name is "+name+",age is"+age; } }
import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:ApplicationContext.xml"}) public class EmpolyeeTest { @Autowired ApplicationContext ctx; @Test public void testEmployee(){ Employee employee =(Employee) ctx.getBean("employee"); assertEquals("zhangsan",employee.getName()); } }
相关文章推荐
- maven下使用junit对spring进行单元测试_01基本应用
- 使用Junit4对由Maven管理的Spring项目进行单元测试
- Maven下使用Junit对Spring进行单元测试
- maven下使用 junit对 spring进行单元测试
- Spring 使用Junit 进行单元测试
- Spring整合JUnit框架进行单元测试代码使用详解
- Spring整合JUnit框架进行单元测试代码使用详解
- 使用Junit对Android应用进行android3.0单元测试
- 在Myeclipse里使用Junit贴图教程与使用JUnit在struts+spring+hibernate框架环境下进行单元测试
- Spring整合JUnit框架进行单元测试代码使用详解
- 在spring下使用junit做单元测试的基本方法
- 使用junit框架对安卓应用进行单元测试 20150412
- 使用Junit对Android应用进行单元测试
- 使用Junit对Android应用进行单元测试
- 使用JUnit在struts+spring+hibernate框架环境下进行单元测试
- (软件项目管理)在eclipse里使用junit进行单元测试以及Maven的学习
- 使用spring配合Junit进行单元测试的总结
- 使用JUnit在struts+spring+hibernate框架环境下进行单元测试
- 使用Junit对Android应用进行单元测试
- Maven项目中使用JUnit进行单元测试