Skip to content

Instantly share code, notes, and snippets.

@prashanth-sams
Last active August 29, 2015 14:07
Show Gist options
  • Save prashanth-sams/642f8bc1ebcff76f98d2 to your computer and use it in GitHub Desktop.
Save prashanth-sams/642f8bc1ebcff76f98d2 to your computer and use it in GitHub Desktop.
package jbehave.main;
import org.jbehave.core.Embeddable;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
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.model.TableTransformers;
import org.jbehave.core.parsers.RegexPrefixCapturingPatternParser;
import org.jbehave.core.parsers.RegexStoryParser;
import org.jbehave.core.reporters.ConsoleOutput;
import org.jbehave.core.reporters.CrossReference;
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 org.jbehave.core.steps.ParameterConverters.DateConverter;
import org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter;
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.*;
public abstract class Basestories extends JUnitStories {
private final CrossReference xref = new CrossReference();
public Basestories() {
configuredEmbedder().embedderControls()
.doGenerateViewAfterStories(true)
.doIgnoreFailureInStories(false)
.doIgnoreFailureInView(true)
.doVerboseFailures(true)
.useThreads(2).useStoryTimeoutInSecs(60);
//configuredEmbedder().useEmbedderControls(new PropertyBasedEmbedderControls());
}
@Override
public Configuration configuration() {
Class<? extends Embeddable> embeddableClass = this.getClass();
Properties viewResources = new Properties();
viewResources.put("decorateNonHtml", "true");
//viewResources.put("reports", "ftl/jbehave-reports-with-totals.ftl");
//Start from default ParameterConverters instance
ParameterConverters parameterConverters = new ParameterConverters();
LocalizedKeywords keywords = new LocalizedKeywords();
//factory to allow parameter conversion and loading from external resources (used by StoryParser too)
ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters, new TableTransformers());
//add custom converters
parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
new ExamplesTableConverter(examplesTableFactory));
return new MostUsefulConfiguration()
.useStoryLoader(new LoadFromClasspath(embeddableClass))
.useStoryParser(new RegexStoryParser(examplesTableFactory))
.useKeywords(keywords)
.useDefaultStoryReporter(new ConsoleOutput(keywords))
.useStoryReporterBuilder(new StoryReporterBuilder()
.withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
.withDefaultFormats()
.withKeywords(keywords)
.withViewResources(viewResources)
.withFormats(CONSOLE, TXT, HTML_TEMPLATE, XML_TEMPLATE)
.withFailureTrace(true)
.withFailureTraceCompression(true)
.withCrossReference(xref))
.useParameterConverters(parameterConverters)
.useStepPatternParser(new RegexPrefixCapturingPatternParser(
"$"))
.useStepMonitor(xref.getStepMonitor());
}
@Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), createSteps());
}
abstract protected List<Object> createSteps();
@Override
protected List<String> storyPaths() {
return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "**/failing_before*.story");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment