如何在 Kohana 中实现 SimpleTest

发布于 2024-08-09 14:01:00 字数 302 浏览 6 评论 0原文

我的老板指派我学习如何使用 Kohana 并在其中实施简单的测试。我们希望将其用作未来项目的框架。

对于 KohanaPHPSimpleTest,我不知道如何对我的助手进行最简单的测试。我什至找不到关于如何将 SimpleTest 连接到 Kohana 的分步教程。

这里有人有想法吗?

My boss assigned me to learn how to use Kohana and implement simple test in that. We would like to use it as our framework for future projects.

Being new to both KohanaPHP and SimpleTest, I can't figure out how to do even the simplest test of my helpers. I can't even find a single step-by-step tutorial on how to attach SimpleTest to Kohana.

Anyone here have an idea?

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

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

发布评论

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

评论(1

完美的未来在梦里 2024-08-16 14:01:00

我们在 Kohana 中创建了一个 SimpleTest_controller

,它从 test 目录中获取测试,

define ( 'SIMPLE_TEST', '../tools/simpletest/');
require_once(SIMPLE_TEST . 'unit_tester.php');
require_once(SIMPLE_TEST . 'reporter.php');
require_once( SIMPLE_TEST . 'mock_objects.php');

class SimpleTest_Controller extends Controller {
  function index() {
    $this->runall();
  }

  function runall() {
    $sDir = '../tests/';
    $rDir = opendir( $sDir );

    while ( $sFile = readdir( $rDir ) ) {
      if ( $sFile != '.' && $sFile != '..' ) {
        $this->run( $sFile );
      }
    }
  }

  function run ( $sTests ) {
    $sDir = '../tests/' . $sTests .'/';
    $rDir = opendir( $sDir );
    $test = new GroupTest( $sTests );

    while ( $sFile = readdir( $rDir ) ) {
      if ( $sFile != '.' && $sFile != '..' && !preg_match('/~\d+~/', $sFile) ) {
        include_once($sDir . $sFile);
        $test->addTestCase( substr($sFile, 0, -4 ) );
      }
    }

    $test->run( new HtmlReporter() );
  }
}

您可以调用 domain.com/simpletest 来运行所有测试
或者如果您的测试文件夹中有 accountfolder,您可以调用 domain.com/simpletest/run/account

We've created a SimpleTest_controller in Kohana

and it gets the test from a directory tests

define ( 'SIMPLE_TEST', '../tools/simpletest/');
require_once(SIMPLE_TEST . 'unit_tester.php');
require_once(SIMPLE_TEST . 'reporter.php');
require_once( SIMPLE_TEST . 'mock_objects.php');

class SimpleTest_Controller extends Controller {
  function index() {
    $this->runall();
  }

  function runall() {
    $sDir = '../tests/';
    $rDir = opendir( $sDir );

    while ( $sFile = readdir( $rDir ) ) {
      if ( $sFile != '.' && $sFile != '..' ) {
        $this->run( $sFile );
      }
    }
  }

  function run ( $sTests ) {
    $sDir = '../tests/' . $sTests .'/';
    $rDir = opendir( $sDir );
    $test = new GroupTest( $sTests );

    while ( $sFile = readdir( $rDir ) ) {
      if ( $sFile != '.' && $sFile != '..' && !preg_match('/~\d+~/', $sFile) ) {
        include_once($sDir . $sFile);
        $test->addTestCase( substr($sFile, 0, -4 ) );
      }
    }

    $test->run( new HtmlReporter() );
  }
}

you can call domain.com/simpletest to run all
or you can call domain.com/simpletest/run/account if you have a accountfolder in your testfolder

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