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

Software testing ความรู้ สำหรับ Tester ผู้ทดสอบ เป็นส่วนสำคัญในการ test โปรแกรม การ ทดสอบโปรแกรมมีความรู้แนะนำไว้ในหมวดนี้

Moderator: mindphp, ผู้ดูแลกระดาน

offing
PHP VIP Members
PHP VIP Members
โพสต์: 1527
ลงทะเบียนเมื่อ: 18/08/2014 10:01 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย offing »

1.ดาวโหลด Symfony ดาวโหลด
2.ติดตั้งไว้ใน htdocs
3.สร้างโฟลเดอร์ไว้สำหรับเก็บไฟล์สำหรับนำไปเทส
4.สร้างไฟล์ phpไว้สำหรับนำไปเทส
1.png
1.png (10.54 KiB) Viewed 1049 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 1049 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 1049 times
7.เลือก testing เลือกโฟลเดอร์ tests
6.png
6.png (32.92 KiB) Viewed 1045 times
5.png
5.png (33.7 KiB) Viewed 1049 times
8.ติ๊ก phpunit
9.เลือก phpunit
7.png
7.png (45.96 KiB) Viewed 1045 times
10.เลือกไฟล์ bootstrap.php.cache และ phpunit.xml.dist
11.คลิกขวาที่ไฟล์ที่จะนำไปเทส กด test
8.png
8.png (18.84 KiB) Viewed 1049 times
12.ผลเทส
9.png
9.png (22.81 KiB) Viewed 1049 times
ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย thatsawan »

:like:
Symfony2 FrameWork : การสร้าง Unit test และการ Run ไฟล์ แบบง่ายๆ
ต่างกันตรงที่ Run บน Netbean กับ Command ค่ะ
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 58