簡體   English   中英

從Java內部動態調用JBehave步驟

[英]Dynamic calling of JBehave steps from inside Java

在Java中,我有一個String對象,該對象具有希望由JBehave匹配並執行的JBehave 如何才能做到這一點? 能做到嗎

我真正想做的是擁有一個包裝器JBehave步驟,該步驟用於檢測另一個任意JBehave步驟。 在調用“內部”步驟之前和之后,它會做一些事情。

所以可以說我已經有以下內容

When I say Hello World

@When("I say $text")
public void iSay(final String text)
{
    System.out.println(text);
}

我希望能夠執行以下操作:

When I repeat 4 times I say Hello World

它會調用:

@When("I repeat $count times $subStepString")
public void repeat(final int repeatCount, final String subStepString)
{
    // prep code here
    for (int i = 0; i < repeatCount; i++)
    {
        howDoIdoThisBitHere(subStepString);
    }
    // post process code here
}

上面寫着howDoIdoThisBitHere(...)的部分應最終不得不JBehave匹配的值subStepString ,如果它是在案件中遇到以上。 這樣,我可以使用此方法來調用其他任意事物。

我不確定這是個好主意,因為step類不應該對核心配置(StepMatchers,Runners等)有任何依賴性,但是這種解決方案是否符合您的需求?

@When("I repeat $count times $subStepString")
public void repeat(final int repeatCount, final String subStepString)
{
    // prep code here
    for (int i = 0; i < repeatCount; i++)
    {
        StoryParser sp = configuration().storyParser();
        Story s = sp.parseStory(subStepString);
        StoryRunner e = configuredEmbedder().storyRunner();
        e.run(configuration(), configuredEmbedder().candidateSteps(), s);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM