0

バージョン 0.9.269 の自動テスト用に、Thucydides(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)

このようにして、Thucydides のようにストーリーを連載できます。

于 2015-05-08T10:50:54.910 に答える