모든 phpunit 테스트를 어떻게 실행합니까?
-
06-07-2019 - |
문제
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 ---configuration phpunit.xml 테스트에 위치한 테스트를 실행하기위한 루트 디렉토리에서/
<phpunit backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Tests">
<directory suffix=".php">Tests</directory>
</testsuite>
</testsuites>
</phpunit>
다른 팁
PHP Test의 파일 이름은 test.php로 끝나야합니다
phpunit mydir
이름이 지정된 모든 스크립트를 실행합니다 xxxxTest.php
디렉토리에서 mydir
(PHPUNIT 문서에 설명되지 않은 모습)
ForphPunit은 자동으로 실행하기로 결정한 것으로 생각합니다. Filename 컨벤션 인 Somethingtest.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;
}
제휴하지 않습니다 StackOverflow