To build a reporter for a single story path with default and given formats:
Class<MyStory> storyClass = MyStory.class; StoryPathResolver resolver = new UnderscoredCamelCaseResolver(); String storyPath = resolver.resolve(storyClass); StoryReporter reporter = new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(storyClass)) .withDefaultFormats().withFormats(TXT, HTML, XML).build(storyPath);
The builder is configured to build with the {@link Format#STATS} as defaultformat. To change the default formats the user can override the method:
new StoryReporterBuilder() { protected StoryReporterBuilder withDefaultFormats() { return withFormats(STATS); } }
The builder configures the file-based reporters to output to the default file directory {@link FileConfiguration#DIRECTORY} as relative to the codelocation. In some case, e.g. with Ant class loader, the code source location from class may not be properly set. In this case, we may specify it from a file:
new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromFile(new File("target/classes"))) .withDefaultFormats().withFormats(TXT, HTML, XML).build(storyPath);
By default, the reporters will output minimal failure information, the single line describing the failure cause and the outcomes if failures occur. To configure the failure trace to be reported as well:
new StoryReporterBuilder().withFailureTrace(true)
If failure trace is reported, it is with the full stack trace. In some cases, it's useful to have it compressed, eliminating unnecessary lines that are not very informative:
new StoryReporterBuilder().withFailureTraceCompression(true)
To specify the use of keywords for a given locale:
new StoryReporterBuilder().withKeywords(new LocalisedKeywords(Locale.IT)
The builder provides default instances for all reporters, using the default output patterns. To change the reporter for a specific instance, e.g. to report format TXT to .text files and to inject other non-default parameters, such as the custom output patterns:
new StoryReporterBuilder(){ public StoryReporter reporterFor(String storyPath, Format format){ FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(storyPath, codeLocation)); switch (format) { case TXT: factory.useConfiguration(new FileConfiguration("text")); Properties customPatterns = new Properties(); customPatterns.setProperty("successful", "{0}(YEAH!!!)\n"); return new TxtOutput(factory.createPrintStream(), customPatterns, keywords); default: return super.reporterFor(format); } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|