我一直在环顾四周,我没有找到任何关于测试套件的好信息,任何人都可以解释一下它应该是什么样子。
我找到了这个例子:
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
你能给我写信或给我看一个测试套件的例子吗?代码的样子。
我的测试文件如下所示:
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)");
}
}