简体   繁体   中英

Codeigniter, Netbeans unittesting with return void functions and db manipulating functions

I am new to unit testing and readying to use test generation supported by netbeans as described in here . It tells to use @assert annotation.

However I am confused here whether,

  1. I need to test all functions?
  2. If all functions to be tested how I can test functions without returning any values.I am using codeigniter, so consider following function which does only loading a view.

     public function index(){ $this->load->view('signup'); } 
  3. Also say I have a function like this in a codeigniter model, is there anyway to creat tests.

     public function save($users_name,$users_email){ $userData = array('users_name'=>$users_name, 'users_email'=>$users_email); $this->db->insert('users',$userData); $user_id = $this->db->insert_id(); return $user_id; } 

I do appreciate if someone could please guide me on above , subjected to using automatic test generation supported by netbeans php ide with or without @assert annotation.

Thank you

GUIR

You don't have to use @assert at all. You can write your test case files by yourself. (Even if you don't have NetBeans.)

  1. It is better to write tests for all public functions, but decide what you test freely.
  2. You could test the controller output (view), if you really want to test it. (It is not pure unit testing.)
  3. If you set your database state to known state, you can test it. Because you know the $user_id value before test execution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM