我一直在環顧四周,我沒有找到關於測試套件的任何好的信息,任何人都可以請解釋它應該是什麼樣子。如何使一個PHP測試套件
我發現這個例子:
require_once 'MyTest.php';
class MySuite extends PHPUnit_Framework_TestSuite
{
public static function suite()
{
return new MySuite('MyTest');
}
protected function setUp()
{
print "\nMySuite::setUp()";
}
protected function tearDown()
{
print "\nMySuite::tearDown()";
}
}
有幾件事我明白,有些不是,我知道我應包括我的測試用例,如包括「test.php的」;
我想製作一個包含我所有測試用例的測試套件,這個測試套件應該怎麼樣?我試過一個例子,我發現在itnernet和我得到這個錯誤信息:
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Argument #1 of PHPUnit_Framework_TestSuite::addTestSuite() must be a class name or object' in C:\xampp\php\pear\PHPUnit\Util\InvalidArgumentHelper.php:69
Stack trace:
#0 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(288): PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class name or o...')
#1 C:\xampp\htdocs\exem\MyTestSuite.php(13): PHPUnit_Framework_TestSuite->addTestSuite('testFunctions')
#2 [internal function]: AllTests::suite('AllTests')
#3 C:\xampp\php\pear\PHPUnit\Runner\BaseTestRunner.php(124): ReflectionMethod->invoke(NULL, 'AllTests')
#4 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(150): PHPUnit_Runner_BaseTestRunner->getTest('mytestsuite', 'C:\xampp\htdocs...', Array)
#5 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#6 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
#7 {main}
thrown in C:\xampp\php\pear\PHPUnit\Util\InvalidArgumentHelper.php on line 69
你能寫信給我或給我的測試套件怎麼看起來像一個例子嗎?代碼如何。
我TESTFILE是這樣的:
include 'functions.php';
class Test extends PHPUnit_Framework_TestCase
{
protected function getConnection()
{
$mysqli = new mysqli('local', 'root', '', 'db_13839918');
if($mysqli->connect_errno > 0){
die('Unable to connect to database [' . $mysqli->connect_error . ']');
}
}
protected function setUp()
{
$mysqli = new mysqli('localhost', 'root', '', 'db_13839918');
$now = time();
$i = 0;
do {
$i = $i+1;
$mysqli->query("INSERT INTO login_attempts (user_id, time) VALUES ('4892388', '$now')");
} while ($i < 6);
}
public function testCheckbrute()
{
$mysqli = new mysqli('localhost', 'root', '', 'db_13839918');
$LessThanFive = checkbrute('4892389', $mysqli);
$this->assertFalse($LessThanFive);
$FiveFailedLogins = checkbrute('4892388', $mysqli);
$this->assertTrue($FiveFailedLogins);
}
public function testLogin()
{
$mysqli = new mysqli('localhost', 'root', '', 'db_13839918');
$AccountIsLockedFalse = Login("xxxxx","xxx", $mysqli);
$this->assertFalse($AccountIsLockedFalse);
$NoUserExists = Login("xxxxxx","xxxxx", $mysqli);
$this->assertFalse($NoUserExists);
}
protected function tearDown()
{
$mysqli = new mysqli('localhost', 'root', '', 'db_13839918');
$mysqli->query("DELETE FROM members WHERE id IN (9, 11)");
}
}
請更新您的問題,以更具體。你不明白哪部分?你遇到什麼錯誤? –
現在它已經升級了 – user2354898