在maven项目中使用Junit的assertThat()方法时,is()方法的使用
2017-09-29 21:25
477 查看
1.要使用is()方法首先需要导入hamcrest-library-1.3.jar和hamcrest-core-1.3.jar两个jar包
依赖配置:
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
import static org.junit.Assert.*;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
public class TestGetName {
@Test
public void testGetName() {
assertThat(new User().getName(),is("mafx"));
}
}
依赖配置:
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
import static org.junit.Assert.*;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
public class TestGetName {
@Test
public void testGetName() {
assertThat(new User().getName(),is("mafx"));
}
}
相关文章推荐
- maven项目使用SOLR时报 previously initiated loading for a different type with name "javax/servlet/http/HttpServletRequest" 错的解决方法
- assertThat的使用方法
- 在Maven项目中使用本地JAR包有两种方法
- JUnit中使用Hamcrest测试框架的assertThat断言
- JUnit中使用Hamcrest测试框架的assertThat断言【4.4新特性】
- web项目中代码引用了本地包,又需要使用maven打war包时,pom的配置方法
- junit 断言assertThat使用
- 项目管理工具:Maven使用方法总结
- 使用Junit4对由Maven管理的Spring项目进行单元测试
- Maven项目在eclipse中使用junit进行单元测试时报错:ClassNotFoundException
- 基于JUnit使用PowerMock的Mockito扩展在Maven测试项目中的配置说明
- maven2创建web项目,使用eclipse没有run on server的解决方法
- 项目管理工具:Maven使用方法总结
- Eclipse使用Maven构建项目运行main方法报ClassNotFoundException
- (软件项目管理)在eclipse里使用junit进行单元测试以及Maven的学习
- Maven项目中使用JUnit进行单元测试
- 解决使用maven的java web项目导入后出现的有关问题 -cannot be read or is not a valid ZIP file
- 在maven项目中使用Junit进行单元测试(一)
- JUnit中使用Hamcrest测试框架的assertThat断言【4.4新特性】
- Junit4中的新断言assertThat的使用方法