หน้า 1 จากทั้งหมด 1

วิธีใช้ Unittest Symfony2 บน Netbean

โพสต์แล้ว: 30/11/2014 3:30 am
โดย offing
1.ดาวโหลด Symfony ดาวโหลด
2.ติดตั้งไว้ใน htdocs
3.สร้างโฟลเดอร์ไว้สำหรับเก็บไฟล์สำหรับนำไปเทส
4.สร้างไฟล์ phpไว้สำหรับนำไปเทส
1.png
1.png (10.54 KiB) Viewed 1071 times

โค้ด: เลือกทั้งหมด

<?php
// src/fortest/Calculator.php
namespace md\testtest;

class Calculator
{
    public function add($a, $b)
    {
        return $a + $b;
    }
    
}

?>
5.สร้างโฟลเดอร์ tests ไว้เก็บไฟล์เทส
3.png
3.png (39.6 KiB) Viewed 1071 times

โค้ด: เลือกทั้งหมด

<?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
4.png (18.93 KiB) Viewed 1071 times
7.เลือก testing เลือกโฟลเดอร์ tests
6.png
6.png (32.92 KiB) Viewed 1067 times
5.png
5.png (33.7 KiB) Viewed 1071 times
8.ติ๊ก phpunit
9.เลือก phpunit
7.png
7.png (45.96 KiB) Viewed 1067 times
10.เลือกไฟล์ bootstrap.php.cache และ phpunit.xml.dist
11.คลิกขวาที่ไฟล์ที่จะนำไปเทส กด test
8.png
8.png (18.84 KiB) Viewed 1071 times
12.ผลเทส
9.png
9.png (22.81 KiB) Viewed 1071 times

Re: วิธีใช้ Unittest Symfony2 บน Netbean

โพสต์แล้ว: 30/11/2014 9:57 am
โดย thatsawan
:like:
Symfony2 FrameWork : การสร้าง Unit test และการ Run ไฟล์ แบบง่ายๆ
ต่างกันตรงที่ Run บน Netbean กับ Command ค่ะ