Come eseguo tutti i miei test PHPUnit?
-
06-07-2019 - |
Domanda
Ho uno script chiamato Script.php e lo testa in Tests / Script.php, ma quando eseguo phpunit Test non esegue alcun test nel mio file di test. Come posso eseguire tutti i miei test con phpunit?
PHPUnit 3.3.17, PHP 5.2.6-3ubuntu4.2, Ubuntu più recente
Output:
$ phpunit Tests
PHPUnit 3.3.17 by Sebastian Bergmann.
Time: 0 seconds
OK (0 tests, 0 assertions)
Ed ecco i miei file di script e test:
script.php
<?php
function returnsTrue() {
return TRUE;
}
?>
Test / 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());
}
}
?>
Soluzione 2
Ho creato seguendo phpunit.xml e ora almeno posso fare phpunit --configuration phpunit.xml nella mia directory principale per eseguire i test che si trovano in Test /
<phpunit backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Tests">
<directory suffix=".php">Tests</directory>
</testsuite>
</testsuites>
</phpunit>
Altri suggerimenti
Il nome file del test Php deve terminare con Test.php
phpunit mydir
eseguirà tutti gli script denominati xxxxTest.php
nella directory mydir
(sembra che non sia descritto nella documentazione di phpunit)
Penso che per PHPUnit di decidere di eseguirlo automaticamente deve seguire una convenzione per il nome del file: somethingTest.php.
Pensi che lo avrebbero documentato. Ho appena consultato il manuale e dicono che puoi passare una directory, ma non come farlo.
Forse il nome della tua classe deve corrispondere al basename (tutto tranne il " .php ") del nome del tuo script di test?
<?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;
}