This is an example set of Cucumber tests for the Java backend. It demonstrates the use of adding Todo items and ensuring that the feature toggle is behaving correctly.
The following is an example of the OFF
state of the feature toggle. Here we are using a Hook to either determine
the state of the feature and fail if it is not set correctly (selective use)
or set the state of the feature (imperative use).
Feature: The todo should allow to add, list and complete features when the feature is off @FEATURE_TITLE_TO_UPPERCASE_OFF Scenario: Add, list and complete features mixed case Given I have a user called "Fred" And I wipe my list of todos When I have added a list of todos | todo | | Buy eggs | | Find cheapest warm white light bulbs | | Organise plumber for garden pump | Then my list of todos should be | todo | | Buy eggs | | Find cheapest warm white light bulbs | | Organise plumber for garden pump |
This isn’t how you would set up a proper Cucumber project, you would use some DI framework, and a bunch of other configuration settings. It is kept simple for this example.
The application needs to know where the Java server is (should be running on http://localhost:3000 by default) and where the Feature Edge server is and what SDK URL it is using.
An example run.sh
is included that you should edit to configure these from the command line. You can use system
properties:
-
edge.hostUrl
orEDGE_HOST_URL
as an environment variable -
edge.sdk
orEDGE_SDK
as an environment variable -
todo.url
- which defaults to http://localhost:3000 if not specified
If you are using the selective option there are some things to remember:
-
You need to set the state of your feature flags before you do your cucumber run, ideally using our Test API. Usage of this is included in the SDK documentation and is included as an example in this project.
-
You need to tag all tests that will have both ON and OFF values. When running cucumber tests pass those same settings from step (1) above as tag selections to your cucumber tests.
If for example you are using our flag for our example FEATURE_TITLE_TO_UPPERCASE and you want
to run the tests where this flag is ON, you must tag those tests that expect it to be off (@FEATURE_TITLE_TO_UPPERCASE_OFF)
and then run your tests with tags="not @FEATURE_TITLE_TO_UPPERCASE_OFF"
. This means it will run all tests excluding
the ones that have been specifically turned off (including non-tagged ones).
If your feature is ON, run with
mvn -Dcucumber.filter.tags="not @FEATURE_TITLE_TO_UPPERCASE_OFF" clean test
Otherwise you will get one failure (you should try this anyway).
If your feature is OFF, run with
mvn -Dcucumber.filter.tags="not @FEATURE_TITLE_TO_UPPERCASE_ON" clean test
The code to check for this is in FeatureHooks
- it will check with the Feature repository for around 3 seconds to
see if the feature is in the right state and if not, will fail with an exception.
In this case, the FeatureHook
will actually set the feature toggle’s value for you, so you can simply do
mvn -Dfeatures.imperative clean test
They should both pass. The features.imperative
system property is being checked for in FeatureHook
class.
If you wish to explore the parallel option, where they both run at the same time, one will always fail and it will be random. A feature cannot be both states across the board at the same time. To do so, edit the pom.xml file and uncommment the parallel option in the pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<!-- <parallel>methods</parallel>-->
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>