我正在关注PHPUnit手册中的示例。请参阅下面的两个测试文件。我正在安装PTI的Eclipse PDT中运行测试。我看到以下问题:
$this->assertTrue(FALSE);
时,我期望失败并跳过测试用例,但所有测试用例都会通过。有没有人经历过类似的事情并解决了这个问题?
DependencyFailureTest
<?php
class DependencyFailureTest extends PHPUnit_Framework_TestCase
{
public function testOne()
{
$this->assertTrue(FALSE);
}
/**
* @depends testOne
*/
public function testTwo()
{
}
}
?>
MultipleDependenciesTest
<?php
class MultipleDependenciesTest extends PHPUnit_Framework_TestCase
{
public function testProducerFirst()
{
$this->assertTrue(true);
return 'first';
}
public function testProducerSecond()
{
$this->assertTrue(true);
return 'second';
}
/**
* @depends testProducerFirst
* @depends testProducerSecond
*/
public function testConsumer()
{
$this->assertEquals(
array('first', 'second'),
func_get_args()
);
}
}
?>
答案 0 :(得分:0)
我还没有一个好的答案,只有一些黑魔法伏都教。我注意到,为了在命令行中运行它,我需要包含被测试的类。
<?php
require_once ('path/to/Car.php')
class CarTest extends PHPUnit_Framework_TestCase {
...
为了在PTI中运行它,我在PHPUnit首选项中的Bootstrap文件中提到了该文件。因此,此reuire_once
语句不是必需的。但更糟糕的是,这个require_once
语句导致测试无法运行!
我注意到有些奇怪的是,即使没有require_once
语句,我的测试也没有运行。在PHPUnit首选项中,我选择了在搜索启用的php / test case类时不检查相同的命名空间。我禁用了它,它起作用了。我再次启用它,它仍然有效。
答案 1 :(得分:0)
Phpunit不显示任何内容(运行0/0)
控制台错误: 致命错误:声明PHPUnitLogger :: addFailure(Test $ test,AssertionFailedError $ e,$ time):void必须与PHPUnit \ Framework \ TestListener :: addFailure(PHPUnit \ Framework \ Test兼容) $ test,PHPUnit \ Framework \ AssertionFailedError $ e,float $ time):无效 C:\ Users \ xxx \ AppData \ Local \ Temp \ phpunit_printer \ PHPUnitLogger.php(415):第1行上的eval()代码
TestCase
<?php
namespace PHPUnit\Framework;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
class SeleniumTest extends \PHPUnit_Framework_TestCase
{
protected $webDriver;
public function setUp()
{
// system . property_exists("Facebook\WebDriver\Firefox\FirefoxDriver", "C:\rc\geckodriver\geckodriver");
// System . set("Webdriver.gecko.driver", "C:\rc\geckodriver\geckodriver");
$this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', DesiredCapabilities::firefox());
$this->webDriver->manage()
->window()
->maximize();
$this->webDriver->get('http://localhost/farmer/login');
// $this->webDriver->get("www.gmail.com");
}
public function testLoginPass()
{
$this->webDriver->get('http://localhost/farmer/login');
$this->webDriver->findElement(WebDriverBy::name('username'))->sendKeys(' correct');
$this->webDriver->findElement(WebDriverBy::id('password'))->sendKeys('password');
$this->webDriver->findElement(WebDriverBy::name('btn-login'))->click();
$content = $this->webDriver->findElement(WebDriverBy::tagName('body'))->getText();
$this->assertContains('Dashboard', $content);
}
public function testLoginFail()
{
$this->webDriver->get('http://localhost/farmer/login');
$this->webDriver->findElement(WebDriverBy::name('mobile'))->sendKeys("800000000000");
$this->webDriver->findElement(WebDriverBy::id('password'))->sendKeys("8000000000");
$this->webDriver->findElement(WebDriverBy::name('btn-login'))->click();
$content = $this->webDriver->findElement(WebDriverBy::className('help-block'))->getText();
$this->assertContains('Your Credential Doesnot Match.Please Try Again !!', $content);
}
public function tearDown()
{
$this->webDriver->quit();
}
}
?>
While MakeGood is working Properly in Eclipse (Everything is OK)
制作结果