Feed4Junit官方地址:
http://databene.org/feed4junit.html
官方文档:
Generating constrained data dynamically
Feed4JUnit supports annotations defined in JSR 303, Java 7 and Benerator 0.7 for generating random data that matches constraints.
As an example see the @Pattern annotation as an example (javax.validation.constraints.Pattern):
@RunWith(Feeder.class) public class RegexTest { @Test public void testSmoke(@Pattern(regexp = "[A-Z][a-z]{3,8}") String name) { System.out.println("name:" + name); } } |
Annotation reference
Annotations marked bold are new in version 1.0:
Annotation | Java Package | Applicability |
Description |
@AssertFalse | javax.validation.constraints | parameter | Requires that a boolean parameter is false |
@AssertTrue | javax.validation.constraints | parameter | Requires that a booöean parameter is true |
@DecimalMin | javax.validation.constraints | parameter | Requires that a number parameter is greater than or equals a minimum value |
@DecimalMax | javax.validation.constraints | parameter | Requires that a number parameter is less than or equals a maximum value |
@Future | javax.validation.constraints | parameter | Requires that a Date parameter is in the future |
@Min | javax.validation.constraints | parameter | Requires that an integral number parameter is greater than or equals a minimum value |
@Max | javax.validation.constraints | parameter | Requires that an integral number parameter is less than or equals a maximum value |
@NotNull | javax.validation.constraints | parameter | Requires that a parameter is not null |
@Null | javax.validation.constraints | parameter | Requires that a parameter is null |
@Past | javax.validation.constraints | parameter | Requires that a Date parameter is in the past |
@Pattern | javax.validation.constraints | parameter | Requires that a String parameter matches a regular expression |
@InvocationCount | org.databene.benerator.anno | method | Limits the number of invocations to a test method |
@Source | org.databene.benerator.anno | method, parameter | Specifies a source file from which to read test data (e.g. CSV or Excel(TM) file) |
@Offset |
org.databene.benerator.anno | method, parameter |
Makes Feed4Junit skip the first n data sets that are imported or generated |
@Distribution | org.databene.benerator.anno | parameter | Specifies a distribution to use for a number parameter |
@Granularity | org.databene.benerator.anno | parameter | Specifies the granularity of a number parameter (corresponds to Benerator's 'precision') |
@Nullquota | org.databene.benerator.anno | parameter | Specifies the quota of null values to generate for a parameter |
@Values | org.databene.benerator.anno | parameter | Specifies a comma-separated list of all supported values |
@Last | org.databene.benerator.anno | parameter |
Used for summary and cleanup functionality necessary after the last call to a test method: The last parameter of a mathod can be annotated with @Last and be made booloean. It will then receive a true value on the last invocation, otherwise false. |
@Generator | org.databene.benerator.anno | method, parameter | Specifies a simple type generator for a parameter or an array generator for a complete parameter set |
@Database | org.databene.benerator.anno |
class, |
Defines a database to be used for data retrieval |
@Bean | org.databene.benerator.anno | class, method |
Defines a custom data generator to retrieve data from |
@Equivalence |
org.databene.benerator.anno |
class, method |
Advises Feed4JUnit to use the EquivalenceGeneratorFactory for all related test methods. It creates relatively small numbers of mean tests using mechanisms from border value and partition testing. |
@Coverage |
org.databene.benerator.anno |
class, method |
Advises Feed4JUnit to use the CoverageGeneratorFactory for all related test methods. It runs through all possible values and all possible combinations and produces a large number of tests. |
@Stochastic |
org.databene.benerator.anno |
class, method |
Advises Feed4JUnit to use the StochasticGeneratorFactory for all related test methods. It creates gentle datarandomly and provides for an unlimited number of tests. |
Smoke Testing
Performing smoke tests with random but valid data can strongly improve code coverage and exhibit bugs from very special data constellations. Even if you cannot simply predict each result of random data, you can check result constraints or at least check for runtime exceptions.
In FeedJUnit, you can use the @Stoachstic annotation to generate random data or the @Coverage annotation to first generate border values and then all values between. Be aware that you need to restrict the InvocationCount in many cases (unless you want to test billions of calls):
@RunWith(Feeder.class) @Test } |
相关推荐
Feed4JUnit能够让编写JUnit的参数化测试变得简便,并为这些测试提供预定义或随机测试数据。它能够从业务分析人员定义好的CVS或 Excel文件读取测试用例数据并在构建/单元测试框架中报告测试成功。利用Feed4JUnit能够...
Feed4JUnit makes it easy to write parameterized tests for the JUnit framework and feed them with predefined or random test data
Junit4使用方法
JUnit4
eclipse上通过一个简单例子演示使用JUnit4进行测试
Junit的简单使用,Junit的简单使用
该文档介绍了如何使用JUNIT4进行单元测试,给出了一个详细的例子
基于Feed4JUnit架构的单元测试技术研究与应用.docx
junit4教程(《Junit4初探》)
junit总结使用例子junit总结使用例子junit总结使用例子
eclipse使用和junit使用
JUnit4概述,在Eclipse中使用JUnit4进行单元测试(初级篇、中级篇、高级篇)
单元测试工具Junit的简单使用
因 jdk5 中的新特性,JUnit4 也因此有了很大的改变。下面详细介绍 JUnit4 的使用方法,只是举个例子说明junit4 的使用
JUnit4使用.pdf,JUnit就是一个可能帮助你在开发Java程序时进行测试的框架,我们将在这一节中尽可能深入地介绍JUnit的相关知识,但由于篇幅所限,本节过后还是有很多东西在等着你来探索,接住我的这块砖头,去发掘出...
Junit4使用教程详解+源码下载.rar
JUnit的使用.doc JUnit的使用.doc
Junit简单使用说明 附带PPT 使用说明比较详细
(在此文档中我使用JUnit的版本为JUnit4.3.1)先检查一下你的Eclipse环境是否已经有编写JUnit测试类的环境了,如果有了就可以直接使用了,如果没有安装,请参考以下操作,如:在Eclipse要安装那些插件和写JUnit测试...
java junit4 jar完整包,junit可用来项目的单元测试。