如何在 simpletest unittest 类中运行单个测试方法?

发布于 2024-09-13 14:55:10 字数 565 浏览 1 评论 0原文

这是我的单元测试类

<?
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 等)都会运行。 有没有办法只执行一个方法?

谢谢, 希哈尔

This is my Unit Test class

<?
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());
?>

When I run this script all methods viz., testAc1, testAc4, testAc7 etc are run.
Is there a way to execute just a single method ?

Thanks,
Shikhar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪淡了忧伤 2024-09-20 14:55:10

在深入研究了 SimpleTest 源代码之后,我发现最简单的方法是重写测试的 getTests() 方法,如下所示,

require_once('simpletest/autorun.php');

class Academic extends UnitTestCase
{
  # .. 
  function testAc7()
  {        
  }

  function getTests()
  {
    return array("testAc7");
  }
}

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

After digging through the SimpleTest source a bit, I have found the easiest way is to override the test's getTests() method as follows,

require_once('simpletest/autorun.php');

class Academic extends UnitTestCase
{
  # .. 
  function testAc7()
  {        
  }

  function getTests()
  {
    return array("testAc7");
  }
}

Here, simply including autorun.php as per usual, only the tests named in getTests() will be run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文