我一直在寻找,我没有找到任何有关测试套件的好信息,有人可以解释它应该是什么样子。
我找到了这个例子:
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)");
}
}
答案 0 :(得分:0)
'MyTest.php'是什么样的?
此错误:
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Argument #1 of PHPUnit_Framework_TestSuite::addTestSuite() must be a class name or object'
表示此行return new MySuite('MyTest');
导致问题。
将其更改为return new MySuite('Test');
传递给MySuite的字符串必须是包含测试的类的名称。
PHPUnit正在寻找一个名为MyTest的类而不是找到它。