2013-03-15 1 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

가 될 것으로 보인다 클래스 폴더에 hello.php를 만들 다른 문제. 내 수업 테스트를 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()); 
    } 



} 
    ?> 

<?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; 
    } 

} 
?> 
관련 문제