0

为版本 0.9.269 的自动化测试实施了一个修昔底德(SERENITY)BDD 环境。我已经看到测试用例的运行者会选择随机的测试故事。有什么办法可以让故事排队吗?PortalTestSuit 的代码如下

public class PortalTestSuite extends ThucydidesJUnitStories {

private static final Logger LOGGER = LoggerFactory.getLogger(PortalTestSuite.class.getName());

/**
 * Instantiates a new Portal test suite.
 */
public PortalTestSuite() {

    /*Some Code to check the server is working or not*/

    /* Do all stories */
    findStoriesCalled("*.story");

}}

在这里,findStories 将从目录中获取随机故事并执行相关代码......但请让我知道将故事排队的方式。谢谢。

4

1 回答 1

0

storyPaths()是的,我们可以通过重写类的方法来维护故事的顺序ThucydidesJUnitStories

@Override
public List<String> storyPaths() {
    try {
        File file = new File(System.getProperty("user.dir").concat("/src/test/resources/StoryContextTest.script"));
        try (FileReader reader = new FileReader(file)) {
            char[] buffer = new char[(int) file.length()];
            reader.read(buffer);
            String[] lines = new String(buffer).split("\n");
            List<String> storiesList = new ArrayList<>(lines.length);
            StoryFinder storyFinder = new StoryFinder();
            for (String line : lines) {
                if (!line.equals("") && !line.startsWith("#")) {
                    if (line.endsWith("*")) {
                        for (URL classpathRootUrl : allClasspathRoots()) {
                            storiesList.addAll(storyFinder.findPaths(classpathRootUrl, line.concat("*/*.story"), ""));
                        }
                    } else {
                        storiesList.add(line);
                    }
                }
            }
            return storiesList;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
private List<URL> allClasspathRoots() {
    try {
        return Collections.list(getClassLoader().getResources("."));
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not load the classpath roots when looking for story files",e);
    }
}

故事被加载StoryContextTest.script

################# Stories goes here #################
stories/authentication/authentication/authentication.story
stories/authentication/authentication/authentication1.story 
(Or)
    */authentication/* (will get stories randomly)

通过这种方式,您可以像在修昔底德中一样连载您的故事。

于 2015-05-08T10:50:54.910 回答