/
CoreStoriesUsingTestNG.java
79 lines (69 loc) · 3.2 KB
/
CoreStoriesUsingTestNG.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package testng;
import org.jbehave.core.Embeddable;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.failures.FailingUponPendingStep;
import org.jbehave.core.i18n.LocalizedKeywords;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.model.ExamplesTableFactory;
import org.jbehave.core.parsers.RegexStoryParser;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.jbehave.core.steps.ParameterConverters;
import testng.steps.CalculatorSteps;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Properties;
import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;
import static org.jbehave.core.reporters.Format.*;
/**
* <p>
* Example of how multiple stories can be run via TestNG.
* </p>
* <p>
* It uses the same configuration as the CoreStories, except that the
* {@link Embeddable#run()} method is annotated by the TestNG
* {@link org.testng.annotations.Test} annotation.
* </p>
*/
//@RunWith(JUnitReportingRunner.class)
public class CoreStoriesUsingTestNG extends JUnitStories {
@Override
public Configuration configuration() {
Class<? extends Embeddable> embeddableClass = this.getClass();
Properties properties = new Properties();
properties.setProperty("encoding", "UTF-8");
// Start from default ParameterConverters instance
ParameterConverters parameterConverters = new ParameterConverters();
// factory to allow parameter conversion and loading from external resources (used by StoryParser too)
ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters);
// add custom converters
parameterConverters.addConverters(new ParameterConverters.DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
new ParameterConverters.ExamplesTableConverter(examplesTableFactory));
return new MostUsefulConfiguration()
.usePendingStepStrategy(new FailingUponPendingStep())
.useStoryParser(new RegexStoryParser(examplesTableFactory))
.useStoryReporterBuilder(new StoryReporterBuilder()
.withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
.withDefaultFormats()
.withViewResources(properties)
.withFormats(CONSOLE, TXT, HTML, XML))
.useParameterConverters(parameterConverters);
}
@Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new CalculatorSteps());
}
@org.testng.annotations.Test
public void run() throws Throwable {
super.run();
}
@Override
protected List<String> storyPaths() {
return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");
}
}