2017-04-16 107 views
0

我無法圍繞這個測試問題纏住我的頭。如何針對SUT的不同實現運行完全相同的phpunit測試?

我寫了測試庫測試其在內存中執行,如:

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

我該怎麼做?

回答

0

好的,我想我知道該怎麼做。

我只需要延長我的初步測試,並重新加載setUp方法是這樣的:

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