【发布时间】:2014-11-19 14:47:01
【问题描述】:
我分叉了 Codeception/Codeception 并添加了一个引发异常的命令模块检查。 测试时,此异常会导致测试失败,但我正在运行测试以强制异常和失败,以确保它捕获它。
这里是对 src/Codeception/Command/GenerateSuite.php 的编辑
if ($this->containsInvalidCharacters ($suite)) {
throw new \Exception("Suite name '{$suite}' contains invalid characters. ([A-Za-z0-9_]).");
}
当我运行命令$I->executeCommand('generate:suite invalid-suite'); 更新测试/cli/GenerateSuiteCept.php 时,它失败了,因为我首先在 src/Codeception/Command/GenerateSuite.php 中抛出了异常。
这是对 tests/cli/GenerateSuiteCept.php 的补充:
$I->executeCommand('generate:suite invalid-dash-suite');
当我运行它时,它说它失败了。但是,我希望它通过,因为我故意添加破折号来验证它是否捕获了无效字符。最好的方法是什么?我对这些测试中的 try/catch 块持谨慎态度。我不确定这是否是最好的方法。
【问题讨论】:
标签: codeception