-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCucumberSplit.java
51 lines (47 loc) · 1.61 KB
/
CucumberSplit.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package io.split.client.testing.cucumber;
import io.cucumber.java.Scenario;
import io.split.client.testing.SplitClientForTest;
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* <p>
* Simple Cucumber plugin for Split.
* </p>
* <p>
* Cucumber scenarios annotated with {@code @split[feature:treatment]} tags can be used to
* configure a {@link SplitClientForTest} instance.
* </p>
* <p>
* To use it, define a <a href="https://cucumber.io/docs/cucumber/api/#hooks">Before Hook</a> that invokes the {@link CucumberSplit#configureSplit(SplitClientForTest, Scenario)}
* method. Example:
* </p>
*
* <pre>
* import io.cucumber.java.Before;
* import io.split.client.testing.SplitClientForTest;
*
* public class StepDefinitions {
* private final SplitClientForTest splitClient = new SplitClientForTest();
*
* @Before
* public void configureSplit(Scenario scenario) {
* CucumberSplit.configureSplit(splitClient, scenario);
* }
* }
* </pre>
*/
public class CucumberSplit {
private static final Pattern SPLIT_TAG_PATTERN = Pattern.compile("^@split\\[(.*):(.*)]");
public static void configureSplit(SplitClientForTest splitClient, Scenario scenario) {
Collection<String> tags = scenario.getSourceTagNames();
for (String tag : tags) {
Matcher matcher = SPLIT_TAG_PATTERN.matcher(tag);
if (matcher.matches()) {
String feature = matcher.group(1);
String treatment = matcher.group(2);
splitClient.registerTreatment(feature, treatment);
}
}
}
}