Toggle
Feature Toggle is common concept in the current software development process, especially if you want to do continous dilivery. But there is a pain for developer to test both Feature Toggle On and Off logic. Because most of Feature Toggle is just a Enum, It's static, It's hard to change the status of one Feature Toggle dynamicly. That's why i write this project. Toggle is a little java tool, which can help you easily test both Feature Toggle on and off logic in one test class.
How-TO
I'm trying to push this project into Maven central repository, Now it's waiting aprroval from Sonatype. when it's done, we can easily using maven depency include this little tool.
step1: Include This Tool Into Your Project
There are three ways to include this tool into your project.
1. Using Maven depency(coming soon)
2. Download the project directly (Download) and add build/libs/Toggle.jar into your project classpath
3. Clone the source codes and add them into your project.
step2:Define Your Own Toggle Class
Your feature toggle class must implements interface Toggle and must using ToggleStatus enum as the switch of Feature Toggle.
public enum MyFeatureToggle implements Toggle {
TEST_FEATURE(ToggleStatus.ON), STAGE1(ToggleStatus.ON), STAGE2(ToggleStatus.OFF);
private ToggleStatus status;
MyFeatureToggle(ToggleStatus status) {
this.status = status;
}
@Override
public void setStatus(ToggleStatus status) {
this.status = status;
}
public boolean isEnabled() {
return status.equals(ToggleStatus.ON);
}
@Override
public ToggleStatus getStatus() {
return status;
}
}
step3: Apply Feature Toggle Test Rule To Your Test Class
Make sure the ToggleRule property is public.
@Rule
public ToggleRule anotherToggleRule = new ToggleRule();
step4: Add Annotation On the Test Method To Decide The Toggle Status When Run This Test
Now, this annotation support single, multiple and mixed Toggles.
@Test
@ToggleEnabled(toggleClass = "example.MyFeatureToggle",toggleNames = "TEST_FEATURE")
public void testEchoToggleOn() throws Exception {
assertThat(server.echo("xianlinbox"), is("Toggle is on, xianlinbox"));
}
@Test
@ToggleEnabled(toggleClass = "example.MyFeatureToggle",toggleNames = {"STAGE1","STAGE2"})
public void testMultipleToggle() throws Exception {
assertThat(server.multipleToggleEcho("xianlinbox"), is("TestFeature is on, Stage 1 is on, Stage 2 is on, xianlinbox"));
}
@Test
@ToggleDisabled(toggleClass = "example.MyFeatureToggle",toggleNames = {"STAGE1","TEST_FEATURE"})
@ToggleEnabled(toggleClass = "example.MyFeatureToggle",toggleNames = "STAGE2")
public void testMixedToggle() throws Exception {
assertThat(server.multipleToggleEcho("xianlinbox"), is("Stage 2 is on, xianlinbox"));
}
@Test
@ToggleDisabled(toggleClass = "example.MyFeatureToggle", toggleNames = {"STAGE1", "TEST_FEATURE"})
@ToggleEnabled(toggleClass = "example.MyFeatureToggle2", toggleNames = "TEST_FEATURE_2")
public void testMixedMultipleToggle() throws Exception {
assertThat(server.multipleToggleEcho("xianlinbox"), is("TestFeature 2 is on, xianlinbox"));
}
That's all , Hope you enjoy it.
Source Code: https://github.com/xianlinbox/Toggle
分享到:
相关推荐
Java 的功能切换 这是一个简单的库,在我参加 TWU 42 时首次完成,感谢Junior Ales我的培训师,它作为开源项目分发。 用法 将您的功能切换设置添加到features.properties资源文件,打开或关闭它,您可以简单地控制...
【标题】"datafx-featuretoggle-8.0b2.zip" 涉及的是一个名为 DataFX 的开源项目,其特色功能是 FeatureToggle。在软件开发中,FeatureToggle(特性开关)是一种策略,允许开发团队在不发布新版本的情况下启用或禁用...
【Laravel开发-laravel-feature-toggle】是一个专注于在Laravel框架中实现特性切换(Feature Toggle)的包,由Joshuaestes开发。特性切换是一种软件开发实践,它允许开发者在不部署新代码的情况下,通过控制台或后台...
标题 "tdd-java-ch09-feature-toggle:Java测试驱动开发第9章" 指向的是一个关于使用Java进行测试驱动开发(TDD)的项目,特别关注的是“功能切换”(feature toggle)这一概念。在软件开发中,功能切换是一种策略,...
功能切换.NET中简单,可靠的功能切换通过NuGet轻松安装FeatureToggle: PM>安装包功能切换关于杰森·罗伯茨贾森·罗伯茨(Jason Roberts)是Microsoft MVP, 拥有超过15年的经验。 他是《 , 和》一书的作者。 他在...
toggleTest.nvim 它在测试文件和实施文件之间切换安装通过插件管理器(推荐)将Plug 'larecg/toggleTest.nvim'添加到您的vimrc文件中。 重新加载您的vimrc或重新启动运行:PlugInstall或类似将Plugin 'larecg/toggle...
"Feature Toggle Extension-crx插件"是一款专为Google Chrome浏览器设计的扩展程序,它支持英文和西班牙文界面。该插件的核心功能是实现"功能开关"(Feature Toggle)的管理,这是一种软件开发中的策略,允许开发...
功能切换关于FeatureToggle是一个易于使用的可扩展库,旨在为PHP应用程序提供功能切换功能。模型库模型基于Toggles,它们是定义用于评估功能是否应打开或关闭(启用或禁用)的算法的类。 例如,一个Toggle会读取配置...
exports = { modules : [ 'nuxt-feature-toggle' ] , featureToggle : { toggles : ( ) => { return Promise . resolve ( { 'my-unique-key' : true } ) } }}作为对象module . exports = { modules : [ 'nuxt-...
npm install aws-feature-toggle 用法 您可以在应用开始传递实例ID的任何地方启动它,就像这样 var ft = require ( 'aws-feature-toggle' ) ; ft . start ( 'i-h725' ) ; 您可以通过将毫秒值作为第二个参数传递给...
"feature-toggle"是一种策略,用于在开发和部署新功能时进行控制,它与AEM/CQ5的CI流程密切相关。 **功能切换(Feature Toggle)**是一种敏捷开发技术,允许开发团队在不中断服务的情况下推出新功能。通过在代码中...
要求ES2017或更高下载及安装将feature-toggle-node安装为依赖项。 将扩展导入到SAP Business Application Studio中。 在扩展程序的根目录中打开命令提示符。 通过在命令提示符中输入以下内容,将feature-toggle-node...
标题 "LEDTOGGLE_ledtoggle_" 暗示我们讨论的主题是关于STM32F411 Nucleo开发板上实现LED灯闪烁的程序。STM32F411 Nucleo是一款基于ARM Cortex-M4内核的微控制器开发板,广泛应用于嵌入式系统设计。"LED TOGGLE"通常...
Passmark's BurnInTest is a software tool that allows all the major sub-systems of a computer to be simultaneously tested for reliability and stability. Status ====== This is a shareware program. ...
功能切换React 概念验证说明在前端react.js项目知识共享功能切换的使用在 。 功能切换可以促进一个界面,该界面公开系统以使用CommonJS模块将功能集成到代码库中,可以在功能完成并准备发布之前(发布切换),也...
Bootstrap Toggle Buttons是一款基于Bootstrap框架的插件,用于创建美观、交互性强的切换按钮。这款插件使得在网页设计中添加开关、选项等控制元素变得更加简便。Bootstrap Toggle Buttons提供了丰富的自定义选项,...
Toggle是unity中常用的控件之一, 该项目是Unity3D中的Toggle使用事件的方式控制交互方式,简单实用。
运行命令“ Source / Test Toggle”,在活动编辑器的源代码和测试文件之间切换。 默认键盘绑定: ctrl + alt + t 设定值 测试关键词 名称: sourceTestToggle.testKeywords 描述:搜索匹配的测试文件时要包括的...
在Unity引擎中,Toggle组件是UI系统的一部分,用于创建用户界面中的开关或复选框功能。Toggle组件在很多场合都非常实用,例如设置选项、选择开关等。本学习笔记将深入探讨Toggle组件及其相关组件ToggleGroup的一些...