【问题标题】:How to run a single test method in simpletest unittest class?如何在 simpletest unittest 类中运行单个测试方法?
【发布时间】:2010-08-12 06:52:04
【问题描述】:

这是我的单元测试课

<?
require_once '../simpletest/unit_tester.php';
require_once '../simpletest/reporter.php';
class Academic extends UnitTestCase
{
    function setUp()
    {
    }
    function tearDown()
    {                           
    }
    function testAc1()
    {          
    } 
    function testAc4()
    {         
    }     
    function testAc7()
    {        
    }

}

$test = new Academic();
$test->run(new HtmlReporter());
?>

当我运行此脚本时,所有方法,即 testAc1、testAc4、testAc7 等都会运行。 有没有办法只执行一个方法?

谢谢, 希哈尔

【问题讨论】:

    标签: simpletest


    【解决方案1】:

    在深入挖掘 SimpleTest 源代码后,我发现最简单的方法是覆盖测试的 getTests() 方法,如下所示,

    require_once('simpletest/autorun.php');
    
    class Academic extends UnitTestCase
    {
      # .. 
      function testAc7()
      {        
      }
    
      function getTests()
      {
        return array("testAc7");
      }
    }
    

    在这里,像往常一样简单地包含 autorun.php,只会运行在 getTests() 中命名的测试。

    【讨论】:

      猜你喜欢
      • 2014-06-16
      • 2011-04-02
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多