是否有可能让子上下文类扩展另一个子上下文并覆盖函数?是否可以覆盖behat上下文中的步骤定义?
目前我有
class TestContext extends BehatContext {
/**
* @Given /^a testScenarioExists$/
*/
public function aTestscenarioexists() {
echo "I am a generic test scenario\n";
}
}
和
class SpecialTestContext extends TestContext {
/**
* @Given /^a testScenarioExists$/
*/
public function aTestscenarioexists() {
echo "I am a special test scenario\n";
}
}
在功能方面,我告诉它我们SpecialTestContext
作为子上下文。
当运行测试贝哈特与
抱怨[贝哈特\贝哈特\异常\ RedundantException]
步骤 “/ ^一个testScenarioExists $ /” 已经在SpecialTestContext定义:: aTestscenarioexists()
请问有人可以用这个指出我的正确方向吗?
给一些进一步的信息,为什么我试图做到这一点我想实现是运行与不同的环境场景的能力,并有小黄瓜文件中指定的环境中,例如:
Scenario: Test with generic environment
Given I am in the environment "generic"
And a test scenario exists
Scenario: Test with specialised environment
Given I am in the environment "specialised"
And a test scenario exists
然后我可以使用在FeatureContext
中添加一些代码来加载正确的子上下文。
只是更新上面提供的链接。 * http://docs.behat.org/en/latest/user_guide/context/definitions.html#redundant-step-definitions * http://docs.behat.org/en/latest/user_guide/context。 html#contexts-lifetime – aczietlow 2017-08-24 17:07:26