Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> PHPUnit2, PHPUnit2
johnnyno
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 21.02.2004

Ostrzeżenie: (0%)
-----


Mam mały problem z PHPUnit2.

Tworzę przykładową klase która bedzie testowana:
Kod
Math.php

class Math {
    public function add($a, $b) {
  return $a + $b;
    }
    
    public function sub($a, $b) {
  return $a - $b;
    }
}


Tworzę dla niej test:
Kod
MathTest.php

require_once("Math.php");
require_once("PHPUnit2\Framework\TestCase.php");

class MathTest extends PHPUnit2_Framework_TestCase {
    private $Math;
    
    public function __construct($name) {
  parent::__construct($name);
    }
    
    public function setUp() {
  $this->Math = new Math();
    }
    
    public function testAdd() {
  $result = $this->Math->add(2, 1);
  $this->assertEquals($result, 3, 0, 'Math->add(1, 2) is not 3');
    }
    
    public function testSub() {
  $result = $this->Math->sub(2, 1);
  $this->assertEquals($result, 1, 0, 'Math->sub(2, 1) is not 1');
    }
}


Jeżeli uruchomię ten test z wiersza polecen (phpunit MathTest test\MathTest.php) to wszystko jest ok (pokazuje wyniki testów).

Natomiast jeżeli wrzucę to w jakis TestSuite, np:
Kod
AllTest.php

require_once("MathTest.php");
require_once("PHPUnit2\Framework\TestSuite.php");
require_once("PHPUnit2\TextUI\TestRunner.php");


$suite = new PHPUnit2_Framework_TestSuite();
$suite->addTest(new MathTest('testAdd'));

PHPUnit2_TextUI_TestRunner::run($test);


Uruchamiam poleceniem phpunit AllTest test\AllTest.php i nic nie ma, żadnych wyników. Nic nie wypisuje na ekranie nawet jesli ustawie wartosci w assertEquals tak zeby wywalalo blad.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 12:41