簡體   English   中英

如何針對SUT的不同實現運行完全相同的phpunit測試?

[英]How to run exactly the same phpunit tests against different implementations of SUT?

我無法解決這個測試問題。

我編寫了一個用於測試存儲庫的測試,該存儲庫使用諸如以下的內存實現:

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 我需要針對新的實現運行完全相同的測試集。 我只想為相同的測試設置另一個上下文。

我怎么做?

好吧,我想我知道該怎么辦。

我只需要擴展我的初始測試並重新加載setUp方法,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM