我想为Phabricator编写一个自定义单元测试。
为此,我查看了在Phabricator中编写单元测试的文档,并在./phabricator/src/infrastructure/testing/testcase/PhabricatorTrivialTestCase.php
创建了一个文件(用于使用平凡的Phabricator测试用例),其中包含以下内容
class PhabricatorTrivialTestCase extends PhabricatorTestCase {
private $two;
public function willRunOneTest($test_name) {
// You can execute setup steps which will run before each test in this
// method.
$this->two = 2;
}
public function testAllIsRightWithTheWorld() {
$this->assertEqual(4, $this->two + $this->two, '2 + 2 = 4');
}
}
当我尝试运行它时,我得到以下消息:
$ cd ./phabricator
$ arc unit src/infrastructure/testing/testcase/
No tests to run.
为什么我不能按照文档运行测试?是不是少了什么步骤?
终于找到了解决办法。
有几件事必须做。
- 将测试文件移动到目录
./src/extensions/__tests__
(文件夹必须是__tests__
) - 将
PhabricatorTrivialTestCase
重命名为SomePhabricatorTrivialTestCase
(因为名称为PhabricatorTrivialTestCase
的测试已经存在) - 运行
arc liberate
(使SomeTrivialPhabricatorTestCase
可用于测试) - 提交修改
- 运行
arc unit --everything
(因为arc unit
返回"没有测试要运行",但arc unit --everything
工作