有谁知道是否有办法强制 CakePHP TestSuite 在失败时查看断言的预期值和结果值?默认情况下,典型的 PHPUnit 测试在输出中显示它,而不是 Cake 的 TestSuite(使用 PHPUnit)。另一方面,当我在 NetBeans 中调试测试用例时,每当我尝试为变量设置监视时,我都会得到某种 Socket 异常,并且它只发生在 CakePHP 测试用例中,它在每个其他源文件中都可以正常工作。这也有解决方案吗?
问问题
499 次
2 回答
0
Ok I somehow worked it out tho the solution will be wiped when u update the Cake Library files. You need to edit the file lib\Cake\TestSuite\Reporter\CakeHtmlReporter
and change the method:
public function paintFail($message, $test)
{
$trace = $this->_getStackTrace($message);
$testName = get_class($test) . '(' . $test->getName() . ')';
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'><pre>" . $this->_htmlEntities($message) . "</pre></div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
}
to:
public function paintFail($message, $test) {
$trace = $this->_getStackTrace($message);
$testName = get_class($test) . '(' . $test->getName() . ')';
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'><pre>" . $this->_htmlEntities($message->getComparisonFailure()->toString()) . "</pre></div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
}
And this will output you something like this when the assertion fails:
Failed asserting that two arrays are equal.--- Expected
+++ Actual
@@ @@
Array (
- 0 => 'Crypto3DS'
- 1 => 'Zlib'
+ 1 => 'Crypto3DS'
+ 2 => 'Zlib'
)
Faster testing in Cake Yeppie :D
于 2012-10-06T09:46:15.650 回答
0
查看 http://www.dereuromark.de/2011/12/04/unit-testing-tips-for-2-0-and-phpunit/
基本上,您可以扩展 TestCase 类并制作自己的附加方法,例如
public function details($is, $expected) {
echo 'is:' . $is; echo '<br />';
echo 'expected: ' . $expected; ob_flush();
}
并在内部调用它或失败时调用它。
或者你只是到处 debug() 。
于 2012-10-05T12:57:59.420 回答