سؤال

لدي برنامج نصي يسمى Script.php واختبارات له في Tests/Script.php، ولكن عندما أقوم بتشغيل اختبارات phpunit، فإنه لا ينفذ أي اختبارات في ملف الاختبار الخاص بي.كيف أقوم بإجراء جميع اختباراتي باستخدام phpunit؟

PHPUnit 3.3.17، PHP 5.2.6-3ubuntu4.2، أحدث أوبونتو

انتاج:

$ phpunit Tests
PHPUnit 3.3.17 by Sebastian Bergmann.
Time: 0 seconds
OK (0 tests, 0 assertions)

وإليكم البرنامج النصي وملفات الاختبار الخاصة بي:

Script.php

<?php  
function returnsTrue() {  
    return TRUE;  
}  
?>

الاختبارات/Script.php

<?php  
require_once 'PHPUnit/Framework.php';  
require_once 'Script.php'  

class TestingOne extends PHPUnit_Framework_TestCase  
{

    public function testTrue()
    {
        $this->assertEquals(TRUE, returnsTrue());
    }

    public function testFalse()
    {
        $this->assertEquals(FALSE, returnsTrue());
    }
}

class TestingTwo extends PHPUnit_Framework_TestCase  
{

    public function testTrue()  
    {  
        $this->assertEquals(TRUE, returnsTrue());  
    }

    public function testFalse()
    {
        $this->assertEquals(FALSE, returnsTrue());
    }
}  
?>
هل كانت مفيدة؟

المحلول 2

لقد أنشأت ما يلي phpunit.xml والآن على الأقل أستطيع أن أفعل phpunit - التكوين phpunit.xml في الدليل الجذر الخاص بي لتشغيل الاختبارات الموجودة في الاختبارات/

<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         syntaxCheck="false">
  <testsuites>
    <testsuite name="Tests">
      <directory suffix=".php">Tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

نصائح أخرى

يجب أن ينتهي اسم ملف اختبار Php بـ Test.php

phpunit mydir سيتم تشغيل كافة البرامج النصية المسماة xxxxTest.php في الدليل mydir

(يبدو أنه لم يتم وصفه في وثائق phpunit)

أعتقد أنه لكي تقرر PHPUnit تشغيلها تلقائيًا، يجب أن تتبع اصطلاح اسم الملف:شيءTest.php.

تعتقد أنهم قد قاموا بتوثيق هذا.لقد نظرت للتو في الدليل، ويقولون أنه يمكنك تمرير الدليل، ولكن ليس في الواقع كيفية القيام بذلك.

ربما يجب أن يتطابق اسم فصلك مع الاسم الأساسي (كل شيء ما عدا ".php") لاسم ملف البرامج النصية للاختبار؟

<?php
//Files required for phpunit test
require_once 'PHPUnit/Framework.php';
//Knowing the drupal environment
require_once './includes/bootstrap.inc';     //initialize the Drupal framework
//Loading the drupal bootstrap
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//Helper file
include_once 'helper.inc';
//Including inc file of addresses module
include_once(module_load_include('inc','addresses_user','addresses_user'));

class addresses_test extends PHPUnit_Framework_TestCase {

protected $uid;

protected function setUp()
{
    $this->uid = 1;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top