【问题标题】:PHPUnit: Testdependencies with test from parentclassPHPUnit:来自父类的测试依赖项
【发布时间】:2010-07-09 13:07:51
【问题描述】:

所以,我的单元测试有点问题。我为不同的测试用例写了一些基础类,我想使用一些准备好的测试方法。

class ModelTestCase extends PHPUnit_Framework_TestCase {
  public function testCreateInstance() { ... }
}

class UserModelTest extends ModelTestCase {
  /**
   * (at)depends testCreateInstance
   */
  public funcion testWhatever($model) { ...}
}

有什么技巧可以让我随心所欲地使用它吗?或者我真的必须在每个班级中编写每个测试吗?

【问题讨论】:

    标签: php unit-testing testing phpunit


    【解决方案1】:

    这完全取决于你真正想要做什么,你的代码示例太模糊了,无法说明。

    您的一个选择是在 ModelTestCase 中创建自己的 setup() 方法(不要忘记调用 parent::setUp())并在那里进行一些初始化。

    【讨论】:

      【解决方案2】:

      如果您只想测试派生模型测试,而不是基类本身,您可以将其声明为抽象:

      abstract class ModelTestCase extends PHPUnit_Framework_TestCase {
        public function testCreateInstance() { ... }
      }
      

      这对我有用。

      【讨论】:

        猜你喜欢
        • 2016-02-06
        • 2016-01-11
        • 1970-01-01
        • 2012-03-02
        • 2016-01-20
        • 2015-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多