ในการ Run Unit test สิ่งเเรกที่จะต้องมี คือ ไฟล์ phpunit.bat
- 27-11-2557 12-35-09.jpg (103.75 KiB) Viewed 1007 times
ในตัวอย่างการสร้างไฟล์เราได้ทำการศึกษาจาก
http://symfony.com/doc/current/book/testing.html
- 27-11-2557 12-36-06.jpg (57.32 KiB) Viewed 1007 times
โค้ด: เลือกทั้งหมด
// src/Acme/DemoBundle/Utility/Calculator.php
namespace Acme\DemoBundle\Utility;
class Calculator
{
public function add($a, $b)
{
return $a + $b;
}
}
โค้ด: เลือกทั้งหมด
// src/Acme/DemoBundle/Tests/Utility/CalculatorTest.php
namespace Acme\DemoBundle\Tests\Utility;
use Acme\DemoBundle\Utility\Calculator;
class CalculatorTest extends \PHPUnit_Framework_TestCase
{
public function testAdd()
{
$calc = new Calculator();
$result = $calc->add(30, 12);
// assert that your calculator added the numbers correctly!
$this->assertEquals(42, $result);
}
}
วิธีการ Run เราจะ Run ผลการทำงานของ Unit test ผ่านทาง Command
- 27-11-2557 12-37-26.jpg (63.41 KiB) Viewed 1007 times
- 27-11-2557 12-38-16.jpg (33.6 KiB) Viewed 1007 times
- 27-11-2557 12-44-44.jpg (86.39 KiB) Viewed 1007 times
กำหนดค่าที่เราจะทำการ Test
กำหนดค่าผลลัพท์ที่เราต้องการ
- 27-11-2557 12-38-31.jpg (38.61 KiB) Viewed 1007 times
คำสั่งที่ใช้ในการ Run
โค้ด: เลือกทั้งหมด
phpunit -c app src/Acme/DemoBundle/Tests/Utility/
- 27-11-2557 12-40-28.jpg (68.96 KiB) Viewed 1007 times
ผลการ Run คำสั่ง Unit test ผ่านไม่มี Erorr
- 27-11-2557 12-41-06.jpg (88.05 KiB) Viewed 1007 times
ที่นี่เรามาเปลี่ยนค่า ให้กับการ test
กำหนดค่าที่เราจะทำการ Test
กำหนดค่าผลลัพท์ที่เราต้องการ
- 27-11-2557 12-41-58.jpg (98.84 KiB) Viewed 1007 times
ผลการ Run คำสั่ง Unit test ไม่ผ่าน มี Erorr เพราะว่าค่าที่ได้ไม่ต้องกับค่าที่เรากำหนดผลลัพท์ไว้