【问题标题】:How to call the assertTrue function using simpletest?如何使用 simpletest 调用 assertTrue 函数?
【发布时间】:2014-04-10 23:58:42
【问题描述】:

我是 php 新手,我正在编写一个测试函数来测试我已经编写的类。但是,我不确定应该如何正确调用函数 assertTrue()。

这是我的代码:

    <?php
    require_once(dirname(__FILE__) . '/simpletest/autorun.php');
    require_once('../db/fileToBeTested.php');

class TestDbManager extends UnitTestCase {

    function TestDbManager(){
        $this->UnitTestCase("Test DB Manager");
    }

    // Function to test if isTableExisting() method works correctly
    function testIsTableExisting() {
        $testDB = new DB("localhost", "root", "password", "GraphAppDB", "3306", "empty@empty.com", true, "GraphApp")
        $this->assertTrue($testDB->isTableExisting("users"), "users table exists");
        $this->assertFalse($testDB->isTableExisting("notAValidTable"), "notAValidTable does not exist");
        $this->assertFalse($testDB->isTableExisting(""));   
    }
}
?>

这是我得到的错误:

解析错误:语法错误,意外'$this' (T_VARIABLE) in /Applications/XAMPP/xamppfiles/htdocs/GraphApp/tests/TestDbManager.php 第 14 行

【问题讨论】:

    标签: php simpletest


    【解决方案1】:

    您在

    之后缺少;
    $testDB = new DB("localhost", "root", "password", "GraphAppDB", "3306", "empty@empty.com", true, "GraphApp")
    

    拨打assertTrue 可能没问题。

    【讨论】:

    • 谢谢!这是一个令人尴尬的错误:P
    猜你喜欢
    • 1970-01-01
    • 2012-06-20
    • 2010-12-01
    • 2018-06-08
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多