วิธีใช้ Unittest Symfony2 บน Netbean
โพสต์แล้ว: 30/11/2014 3:30 am
1.ดาวโหลด Symfony ดาวโหลด
2.ติดตั้งไว้ใน htdocs
3.สร้างโฟลเดอร์ไว้สำหรับเก็บไฟล์สำหรับนำไปเทส
4.สร้างไฟล์ phpไว้สำหรับนำไปเทส
5.สร้างโฟลเดอร์ tests ไว้เก็บไฟล์เทส
6.คลิกขวาเลือก properties ที่ไฟล์โปรเจค
7.เลือก testing เลือกโฟลเดอร์ tests
8.ติ๊ก phpunit
9.เลือก phpunit 10.เลือกไฟล์ bootstrap.php.cache และ phpunit.xml.dist
11.คลิกขวาที่ไฟล์ที่จะนำไปเทส กด test 12.ผลเทส
2.ติดตั้งไว้ใน htdocs
3.สร้างโฟลเดอร์ไว้สำหรับเก็บไฟล์สำหรับนำไปเทส
4.สร้างไฟล์ phpไว้สำหรับนำไปเทส
โค้ด: เลือกทั้งหมด
<?php
// src/fortest/Calculator.php
namespace md\testtest;
class Calculator
{
public function add($a, $b)
{
return $a + $b;
}
}
?>
โค้ด: เลือกทั้งหมด
<?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);
}
}
9.เลือก phpunit 10.เลือกไฟล์ bootstrap.php.cache และ phpunit.xml.dist
11.คลิกขวาที่ไฟล์ที่จะนำไปเทส กด test 12.ผลเทส