Zend Studio 和 PHPUnit 入门问题

发布于 2024-11-04 18:44:03 字数 1915 浏览 5 评论 0原文

我正在尝试创建我的第一个单元测试。我使用 Zend Studio,并且已将 phpUnit 库添加到我的项目中,方法是:

Project ->属性->添加库

当我将其作为 PHP 单元测试运行时,出现以下错误:

无法运行 PHPUnit 会话。只有 PHPUNIT 类可以作为 PHPUnit 测试运行。原因:在 IndexControllerTest.php 中找不到测试

IndexControllerTest.php:

<?php
require_once 'application\controllers\IndexController.php';
require_once 'PHPUnit\Framework\TestCase.php';
/**
 * IndexController test case.
 */
class IndexControllerTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var IndexController
     */
    private $IndexController;
    /**
     * Prepares the environment before running a test.
     */
    protected function setUp ()
    {
        parent::setUp();
        // TODO Auto-generated IndexControllerTest::setUp()
        $this->IndexController = new IndexController(/* parameters */);
    }
    /**
     * Cleans up the environment after running a test.
     */
    protected function tearDown ()
    {
        // TODO Auto-generated IndexControllerTest::tearDown()
        $this->IndexController = null;
        parent::tearDown();
    }
    /**
     * Constructs the test case.
     */
    public function __construct ()
    {
        // TODO Auto-generated constructor
    }
    /**
     * Tests IndexController->init()
     */
    public function testInit ()
    {
        // TODO Auto-generated IndexControllerTest->testInit()
        $this->markTestIncomplete("init test not implemented");
        $this->IndexController->init(/* parameters */);
    }
    /**
     * Tests IndexController->indexAction()
     */
    public function testIndexAction ()
    {
        // TODO Auto-generated IndexControllerTest->testIndexAction()
        $this->markTestIncomplete("indexAction test not implemented");
        $this->IndexController->indexAction(/* parameters */);
    }
}

我该如何解决这个问题?

I am trying to create my first unit test. I use Zend Studio, and I have added the phpUnit library to my project by going to:

Project -> Properties -> Add Library

When I run it as PHP Unit Test I get the following error:

Unable to run a PHPUnit session. Only PHPUNIT classes can be run as PHPUnit tests. Reason: Not tests found in IndexControllerTest.php

IndexControllerTest.php:

<?php
require_once 'application\controllers\IndexController.php';
require_once 'PHPUnit\Framework\TestCase.php';
/**
 * IndexController test case.
 */
class IndexControllerTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var IndexController
     */
    private $IndexController;
    /**
     * Prepares the environment before running a test.
     */
    protected function setUp ()
    {
        parent::setUp();
        // TODO Auto-generated IndexControllerTest::setUp()
        $this->IndexController = new IndexController(/* parameters */);
    }
    /**
     * Cleans up the environment after running a test.
     */
    protected function tearDown ()
    {
        // TODO Auto-generated IndexControllerTest::tearDown()
        $this->IndexController = null;
        parent::tearDown();
    }
    /**
     * Constructs the test case.
     */
    public function __construct ()
    {
        // TODO Auto-generated constructor
    }
    /**
     * Tests IndexController->init()
     */
    public function testInit ()
    {
        // TODO Auto-generated IndexControllerTest->testInit()
        $this->markTestIncomplete("init test not implemented");
        $this->IndexController->init(/* parameters */);
    }
    /**
     * Tests IndexController->indexAction()
     */
    public function testIndexAction ()
    {
        // TODO Auto-generated IndexControllerTest->testIndexAction()
        $this->markTestIncomplete("indexAction test not implemented");
        $this->IndexController->indexAction(/* parameters */);
    }
}

How do I fix that?

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

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

发布评论

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

评论(1

顾挽 2024-11-11 18:44:03

您必须删除测试用例的 __construct() 方法。 PHPUnit 将参数传递给构造函数,因此您必须将它们传递给 parent::__construct() 或者(更可能的是)完全删除构造函数。

另外,如果您正在使用 Zend Framework 并测试 Zend_Controller_Action 类,您可能需要考虑使用 Zend_Test_PHPUnit_ControllerTestCase 因为它为您提供了大量的脚手架。请注意,每个测试都会从一条路线直接到达渲染的内容,这可能不够细粒度以满足您的需求。它不适合我们,所以我分别为控制器和视图创建了基本测试用例类。

You must remove the test case's __construct() method. PHPUnit passes parameters to the constructor so you must either pass them along to parent::__construct() or--more likely--remove the constructor entirely.

Also, if you are using Zend Framework and testing Zend_Controller_Action classes, you may want to consider using Zend_Test_PHPUnit_ControllerTestCase as it provides a lot of scaffolding for you. Note that each test will go from a route straight through to the rendered content which might not be fine-grained enough for your needs. It wasn't for ours so I created base test case classes for controllers and views separately.

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