dpjhq00684
2014-07-24 03:52
浏览 32
已采纳

如何让behat知道使用哪个功能上下文?

how to let behat know which context to use?, because by default,there is this FeatureContext.php inside the features folder, whereby, when the behat runs, it will use that file while the .feature file is running (scenarios)...the problem is, if I have alot of modules to test, ofcourse, I cannot just lump all of those functions inside one FeatureContext.php file right?, I would want to name different contexes and different .feature files, so how to let behat know which context and .feature file to run?

this is the line of command that i use to fire behat

/export/home/project/htdocs/bdd/bin/behat --profile phantomjs-via-webdriver

图片转代码服务由CSDN问答提供 功能建议

如何让behat知道要使用哪个上下文?因为默认情况下,功能内部有这个FeatureContext.php 文件夹,当behat运行时,它将在.feature文件运行时使用该文件(方案)...问题是,如果我有很多模块要测试,当然,我不能把所有这些功能都归结为 在一个FeatureContext.php文件中,我想要命名不同的上下文和不同的.feature文件,那么如何让behat知道要运行哪个上下文和.feature文件?

这是 我用来触发的命令行

  / export / home / project / htdocs / bdd / bin / behat --profile phantomjs-via-webdriver 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drt12345678 2014-07-24 06:28
    已采纳

    Behat uses all of the contexts you specify, the only way out of this is to specify only the context(s) you want to use. Depending on the Behat version the syntax also differs. For Behat 2 this answer explains one strategy. For Behat 3 you can do the following:

    default:
        suites:
            module1:
                contexts:
                    - 'FeatureContext1'
                    - 'FeatureContext2'
            module2:
                contexts:
                    - 'FeatureContext1'
                    - 'FeatureContext3'
    

    My two cents: I don't have a tiniest idea about your app, but don't confuse functional and unit testing (if you do). There can be different situations when you benefit from per module contexts, like "authorisation", "admin", or "comments", but their only purpose is to separate code from the overall context into a more manageable chunks. They still work together and cover the entire application (or a very distinct part of it). Testing module-specific functionality would be a lot easier with a unit test framework, which ensures that the modules works on their own.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题