【问题标题】:How to run exactly the same phpunit tests against different implementations of SUT?如何针对 SUT 的不同实现运行完全相同的 phpunit 测试?
【发布时间】:2017-04-16 17:36:37
【问题描述】:

我无法解决这个测试问题。

我为测试存储库编写了一个测试,它使用内存实现,例如:

class RepositoryTest extends TestCase {

    function setUp() {
        // set implementation in the container
        container()->set(Repository::class, InMemoryRepository::class);
    }

    function test_it_can_save() {...}
    function test_it_can_delete() {...}
    function test_it_can_query() {...}
}

然后我为这个存储库添加了另一个实现。假设它是SQLRepository。 我需要针对我的新实现运行完全相同的测试集。 我想为相同的测试设置另一个上下文。

我该怎么做?

【问题讨论】:

    标签: php phpunit tdd ioc-container


    【解决方案1】:

    好吧,我想我知道该怎么做了。

    我只需要扩展我的初始测试并重新加载setUp 方法,如下所示:

    class SQLRepositoryTest extends RepositoryTest {
        function setUp() {
            // set another implementation in the container
            container()->set(Repository::class, SQLRepository::class);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 2018-05-28
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      相关资源
      最近更新 更多