1.ดาวโหลด Symfony
ดาวโหลด
2.ติดตั้งไว้ใน htdocs
3.สร้างโฟลเดอร์ไว้สำหรับเก็บไฟล์สำหรับนำไปเทส
4.สร้างไฟล์ phpไว้สำหรับนำไปเทส

- 1.png (10.54 KiB) Viewed 561 times
Code: Select all
<?php
// src/fortest/Calculator.php
namespace md\testtest;
class Calculator
{
public function add($a, $b)
{
return $a + $b;
}
}
?>
5.สร้างโฟลเดอร์ tests ไว้เก็บไฟล์เทส

- 3.png (39.6 KiB) Viewed 561 times
Code: Select all
<?php
// src/Acme/DemoBundle/Tests/Utility/CalculatorTest.php
namespace md\testtest;
use md\testtest\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);
}
public function testAdd2()
{
$calc = new Calculator();
$result = $calc->add(30, 13);
// assert that your calculator added the numbers correctly!
$this->assertEquals(42, $result);
}
public function testAdd3()
{
$calc = new Calculator();
$result = $calc->add(30, 10);
// assert that your calculator added the numbers correctly!
$this->assertEquals(40, $result);
}
}
6.คลิกขวาเลือก properties ที่ไฟล์โปรเจค

- 4.png (18.93 KiB) Viewed 561 times
7.เลือก testing เลือกโฟลเดอร์ tests

- 6.png (32.92 KiB) Viewed 557 times

- 5.png (33.7 KiB) Viewed 561 times
8.ติ๊ก phpunit
9.เลือก phpunit

- 7.png (45.96 KiB) Viewed 557 times
10.เลือกไฟล์ bootstrap.php.cache และ phpunit.xml.dist
11.คลิกขวาที่ไฟล์ที่จะนำไปเทส กด test

- 8.png (18.84 KiB) Viewed 561 times
12.ผลเทส

- 9.png (22.81 KiB) Viewed 561 times