프로그래밍/PHP

코드이그나이터(CodeIgniter) 유닛 테스트(Unit Test) 시험

채윤아빠 2019. 1. 28. 15:50
728x90
반응형



Unit Test Controller를 작성하여 시험하는 방법

  • 브라우저에서 해당 Controller를 호출하여 시험 결과를 확인하는 방식
  • 특정 시점에서 단위 시험 결과를 리포팅 받아 정리하는 용도 정도로 활용 가능
  • Continous Integration에는 적합하지 않음
  • 관련 예제

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    <?php
    /**
     * 단위 시험(Unit Test) 예제
     *
     * @package WebBuilder
     * @file    unit_test.php
     * @author  hbesthee@naver.com
     * @since   2019-01-25
     * @copyright   Copyright (c) 2019, hbesthee
     * @version 0.0.1
    */
    defined('BASEPATH') OR exit('No direct script access allowed');
     
    class UnitTest extends CI_Controller
    {
        public function __construct()
        {
            parent::__construct();
     
            $this->load->library('unit_test');
     
            $this->load->model('shopadmin/shopadmin');
            $this->load->model('goods_model');
        }
     
        function index()
        {
            echo "단위 시험 실행";
     
            $test = 1 + 1;
            $expected_result = 2;
            $test_name 'Adds one plus one';
            $this->unit->run($test$expected_result$test_name);
     
            $category_list $this->goods_model->get_catrgory_all();
            $this->unit->run($category_list"is_array""get_catrgory_all");
     
            echo $this->unit->report();
     
            echo "<p /><pre>";
            print_r( $this->unit->result() );
            echo "</pre>";
        }
    }
    ?>

동작 예시


참고자료