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 } |
相关推荐
开发者会使用约束布局(ConstraintLayout)、线性布局(LinearLayout)或相对布局(RelativeLayout)来组织这些组件。 3. **数据获取** 为了展示新闻,应用需要从网络获取数据,通常采用JSON格式。这可能涉及到...
scratch少儿编程逻辑思维游戏源码-米克 demo.zip
scratch少儿编程逻辑思维游戏源码-萝卜男孩拯救世界.zip
scratch少儿编程逻辑思维游戏源码-酷忍者.zip
教育科技_微信小程序_二手交易平台_大学校园二手书与物品循环利用公益系统_风华读书人校园二手交易平台_基于C2C模式的校内闲置物品交易系统_支持多校区独立运营的二手书交易平台_包含
全新UI彩虹外链网盘系统源码前后端美化模板整站 模版文件.zip
maoxig_nonebot-plugin-ai-timetable_32152_1745865455265
少儿编程scratch项目源代码文件案例素材-足球顶尖高手.zip
少儿编程scratch项目源代码文件案例素材-作战基地.zip
少儿编程scratch项目源代码文件案例素材-云端之上 1-4名玩家.zip
scratch少儿编程逻辑思维游戏源码-魔幻之塔.zip
scratch少儿编程逻辑思维游戏源码-楼层酷跑.zip
scratch少儿编程逻辑思维游戏源码-圈.zip
少儿编程scratch项目源代码文件案例素材-纸片马里奥自定义战役.zip
少儿编程scratch项目源代码文件案例素材-自由下落.zip
少儿编程scratch项目源代码文件案例素材-阻击蜈蚣.zip
健康监测与疾病预防_脉搏波分析_六轴加速度传感器_生理参数融合_STC12硬件采集_Android数据处理_SpringBoot后端_MySQL数据库_MatlabPython实验
音乐流媒体应用开发_基于JetpackCompose的跨平台开发_网易云音乐风格的多终端音乐播放器_包含手机平板电视手表四端适配的现代化音乐播放应用实现音乐发现播放列表管理个性化推
移动应用开发_Android_Kotlin_Jetpack_开源框架_课程表应用_学生管理_教育信息化_云舒课表_智能课表_课表提醒_成绩查询_主题定制_背景更换_自动静音_校园生
嵌入式系统开发_JavaScript运行时_Lvgl图形库绑定_基于Mooncake框架的智能手表UI开发平台_支持HAL硬件抽象层API调用_提供过渡动画特效_用于构建可穿戴设备