Introduction on Using Hamcrest Unit Test Framework
2014-08-27 18:57
549 查看
Hamcrest is a unit test framework, the assert function assertThat of hamcrest is more human readable comparing to the assert function of Junit, therefore, Junit4 has already adopted and integrated the hamcrest framework from version 4.4 on. Please check
following screenshot.
But Junit4 integrates only the core features of hamcrest, in order to facilitate our test automation work, we should add the hamcrest JAR library with all features into our test project.
- Hamcrest-all-xx.jar : Contains all feature of hamcrest
- Hamcreset-core-xx.jar : Contains core feature of hamcrest
We could download hamcrest by following this link:
http://search.maven.org/#search|ga|1|g%3Aorg.hamcrest
Following description would illustrate how to use hamcrest-all in our test project.
Step 1:Drag&drop the hamcrest-all jar package to the libs(Create one if not exist)folder of the project
Step 2: Import hamcrest modules into test script
- “importstatic org.hamcrest.MatcherAssert.assertThat”: in order to use the function“assertThat”
- “import static org.hamcrest.Matchers.*”:in order to use the matcher of“is”,”notNullValue”,”equalTo” and so on.
Step 3: Use hamcrest feature in our test script
Following are the link on the syntax of asserThat function of hamcrest.
http://langgufu.iteye.com/blog/1893927
-----------------------------------------TheEnd--------------------------------------
following screenshot.
But Junit4 integrates only the core features of hamcrest, in order to facilitate our test automation work, we should add the hamcrest JAR library with all features into our test project.
- Hamcrest-all-xx.jar : Contains all feature of hamcrest
- Hamcreset-core-xx.jar : Contains core feature of hamcrest
We could download hamcrest by following this link:
http://search.maven.org/#search|ga|1|g%3Aorg.hamcrest
Following description would illustrate how to use hamcrest-all in our test project.
Step 1:Drag&drop the hamcrest-all jar package to the libs(Create one if not exist)folder of the project
Step 2: Import hamcrest modules into test script
- “importstatic org.hamcrest.MatcherAssert.assertThat”: in order to use the function“assertThat”
- “import static org.hamcrest.Matchers.*”:in order to use the matcher of“is”,”notNullValue”,”equalTo” and so on.
Step 3: Use hamcrest feature in our test script
Following are the link on the syntax of asserThat function of hamcrest.
http://langgufu.iteye.com/blog/1893927
-----------------------------------------TheEnd--------------------------------------
相关文章推荐
- Introduction on Using Hamcrest Unit Test Framework
- An Introduction to Using Binder Framework on Android Operating System
- Introduction to unittest using python
- Introduction to unittest using python
- C++ Unit Testing Framework: A Boost Test Tutorial——part2:Using Boost Test
- C++ Unit Testing Framework: A Boost Test Tutorial——part1:Boost Test crash-course
- testngpp - next generation unit test framework for c/c++
- Create Unit Test on VS
- VisualStudio UnitTest FrameWork
- 使用 Visual Studio 2005 Team System 进行单元测试并生成用于 Unit Test Framework 的源代码
- 使用 Visual Studio 2005 Team System 进行单元测试并生成用于 Unit Test Framework 的源代码
- GAE unit test framework: GAEUnit
- 使用 Visual Studio 2005 Team System 进行单元测试并生成用于 Unit Test Framework 的源代码
- How to write good test cases using Robot Framework
- 使用 Visual Studio 2005 Team System 进行单元测试并生成用于 Unit Test Framework 的源代码
- how to learn unit test mock framework
- Using MVC improve UI Unit Test
- lua unit test introduction
- Using TestContext in Unit Tests
- 使用 Visual Studio 2005 Team System 进行单元测试并生成用于 Unit Test Framework 的源代码(详解)