2013-03-15 4 views
1

Вот мои два тестовых случай:SimpleTest (PHP блок тестер) представляется отчет неправильного подсчета испытаний случая

<?php 
require_once(dirname(__FILE__) . '/../simpletest/unit_tester.php'); 

class Tests extends UnitTestCase { 
    function test_1() { 
     $this->assertTrue(true); 
    } 
    function test_2() { 
     $this->assertTrue(true); 
    } 
} 
?> 

и мой тестовый драйвер:

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

$test = new TestSuite(); 
$test->addFile(dirname(__FILE__) . '/ex1.php'); 
$test->run(new TextReporter()); 
?> 

я получаю этот выход:

TestSuite 
OK 
Test cases run: 1/2, Passes: 2, Failures: 0, Exceptions: 0 

при запуске файла драйвера (ex2.php), подобного этому с терминала:

curl 'http://localhost/~marc/simpletestexample/ex2.php' 

Теперь, почему он сообщает «Пробеги для испытаний: 1/2», а не «Испытательные случаи: 1/1»? Кажется, что где-то есть фантомный тест, который не запускается.

+0

http://stackoverflow.com/questions/13060495/strange-thing-using-simple-test-in-php –

+0

, кажется, другая проблема. Я сменил свои тесты класса на MyTests с точно таким же результатом. В моем случае проблема заключается не в том, что мой тест не выполняется, но, похоже, это случай, который не является моим, который не запускается. –

+0

@ CanGeliş Это не та же проблема, на которую вы дали ссылку. Это происходит независимо от того, что мы делаем, но это показывает 1/2. Ссылка, которую вы дали, там пользователь не запустил имя функции правильно с тестом. – rashidkhan

ответ

0
<?php 
    require_once(dirname(__FILE__) . '/simpletest/autorun.php'); 
    require_once('/classes/hello.php');  
    class Testhello extends UnitTestCase { 
    function testViewhelloWithEntries() 
    { 
     $hello= new hello(); 
     $hello->add("Bob", "Hi, I'm Bob."); 
     $hello->add("Tom", "Hi, I'm Tom."); 
     $hello->add("jack", "Hi, I'm Jack."); 
     $entries = $hello->viewAll(); 
     $count_is_greater_than_zero = (count($entries) > 0); 
     $this->assertTrue($count_is_greater_than_zero); 
     $this->assertIsA($entries, 'array'); 
     foreach($entries as $entry) { 
      $this->assertIsA($entry, 'array'); 
      $this->assertTrue(isset($entry['name'])); 
      $this->assertTrue(isset($entry['message'])); 
     } 
    } 
    public function hi($name ,$message) 
    { 
     self::$_entries[] = array('name' => $name, 'message' => $message); //fixed! 
    return true; 
    } 
    function testViewhelloWithNoEntries() 
    { 
     $hello = new hello(); 
     $hello->deleteAll(); // Delete all the entries first so we know it's an empty table 
     $hello->jay(); 
     $entries = $hello->viewAll(); 
     $this->assertEqual($entries, array()); 
    } 



} 
    ?> 

создать hello.php в папке классов

<?php 
class hello 
{ 
private static $_entries = array( 
     array ( 
      'name' => 'Kirk', 
      'message' => 'Hi, I\'m Kirk.' 
     ), 
     array ( 
      'name' => 'Ted', 
      'message' => 'Hi, I\'m Ted.' 
     ) 
    ); 




public function viewAll() { 
     // Here, we should retrieve all the records from the database. 
     // This is simulated by returning the $_entries array 
     return self::$_entries; 
    } 

    public function add($name, $message) { 
     // Here, we simulate insertion into the database by adding a new record into the $_entries array 
     // This is the correct way to do it: self::$_entries[] = array('name' => $name, 'message' => $message); 
     // print_r( self::$_entries[] = array('name' => $name, 'message' => $message)); //oops, there's a bug here somewhere 
     echo " <br> "; 
    echo "My name is a {$name}"."&nbsp;"."{$message}"; 
     return true; 
    } 

    public function deleteAll() { 
     // We just set the $_entries array to simulate 
     self::$_entries = array(); 
     return true; 
    } 
    public function jay() { 

     // We just set the $_entries array to simulate 
     //echo "hello world"; 
     self::$_entries = array(); 
     return true; 
    } 

} 
?>