JUnit记者没有显示JBehave中每个步骤的详细报告

时间:2013-04-04 08:41:44

标签: automation report jbehave

我正在尝试设置JBehave来测试Web服务。

模板故事运行良好,但我只能在JUnit Panel中看到Acceptance套件类的执行结果。我想要的是查看套件中每个故事的执行结果以及故事中的每个步骤,如简单的JUnit测试或Thucydides框架中所示。

这是我的接受套件类:所以也许我没有配置某些东西,或者我必须以其他方式记录我的步骤方法,但我还没有找到答案。

package ***.qa_webservices_testing.jbehave;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.jbehave.core.Embeddable;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
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.parsers.RegexPrefixCapturingPatternParser;
import org.jbehave.core.reporters.CrossReference;
import org.jbehave.core.reporters.Format;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ***.qa_webservices_testing.jbehave.steps.actions.TestAction;

/**
 * suite class.
 */
public class AcceptanceTestSuite extends JUnitStories {
    private static final String CTC_STORIES_PATTERN = "ctc.stories";
    private static final String STORY_BASE = "src/test/resources";
    private static final String DEFAULT_STORY_NAME = "stories/**/*.story";
    private static final Logger LOGGER = LoggerFactory.getLogger(AcceptanceTestSuite.class);

    private final CrossReference xref = new CrossReference();

    public AcceptanceTestSuite() {
        configuredEmbedder()
            .embedderControls()
            .doGenerateViewAfterStories(true)
            .doIgnoreFailureInStories(false)
            .doIgnoreFailureInView(true)
            .doVerboseFailures(true)
            .useThreads(2)
            .useStoryTimeoutInSecs(60);
    } 

    @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();
        return new MostUsefulConfiguration()
            .useStoryLoader(new LoadFromClasspath(embeddableClass))
            .useStoryReporterBuilder(new StoryReporterBuilder()
                .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
                .withDefaultFormats()
                .withViewResources(viewResources)
                .withFormats(Format.CONSOLE, Format.TXT, Format.HTML_TEMPLATE, Format.XML_TEMPLATE)
                .withFailureTrace(true)
                .withFailureTraceCompression(false)
                .withMultiThreading(false)               
                .withCrossReference(xref)) 
            .useParameterConverters(parameterConverters)                     
            // use '%' instead of '$' to identify parameters
            .useStepPatternParser(new RegexPrefixCapturingPatternParser(
                            "%")) 
            .useStepMonitor(xref.getStepMonitor());
    }

    @Override
    protected List<String> storyPaths() {
        String storiesPattern = System.getProperty(CTC_STORIES_PATTERN);
        if (storiesPattern == null) {
            storiesPattern = DEFAULT_STORY_NAME;
        } else {
            storiesPattern = "**/" + storiesPattern;
        }
        LOGGER.info("will search stories by pattern {}", storiesPattern);
        List<String> result = new StoryFinder().findPaths(STORY_BASE, Arrays.asList(storiesPattern), Arrays.asList(""));
        for (String item : result) {
            LOGGER.info("story to be used: {}", item);
        }
        return result;
    }

    @Override
    public InjectableStepsFactory stepsFactory() {
        return new InstanceStepsFactory(configuration(), new TestAction());
    }
}

我的测试方法如下:

Customer customer = new cutomer();

@Given ("I have Access to Server")
public void givenIHaveAccesToServer() {
    customer.haveAccesToServer();
}

所以他们只有JBehave符号记录。

Junit面板中返回的结果只是像这里一样(我没有权利发布图片):

enter image description here

2 个答案:

答案 0 :(得分:2)

是的,Codecentric runner非常好用。 https://github.com/codecentric/jbehave-junit-runner Eclipse Juno and the CodeCentric Runner.

答案 1 :(得分:1)

你应该试试这个开源库:

https://github.com/codecentric/jbehave-junit-runner

它完全符合您的要求:)