简体   繁体   English

Codeigniter,NetBeans单元测试以及返回void函数和db操纵函数

[英]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 . 我是新来的单元测试并准备好使用由NetBeans的支持测试生成中所描述这里 It tells to use @assert annotation. 它告诉使用@assert批注。

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. 如果要测试所有函数,如何在不返回任何值的情况下测试函数。我正在使用codeigniter,因此请考虑以下仅加载视图的函数。

     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. 还说我在codeigniter模型中有一个类似这样的函数,无论如何都可以创建测试。

     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. 如果有人可以指导我,请使用netbeans php ide支持的自动测试生成(带有或不带有@assert注释),我对此表示感谢。

Thank you 谢谢

GUIR 图形用户界面

You don't have to use @assert at all. 您根本不需要使用@assert。 You can write your test case files by yourself. 您可以自己编写测试用例文件。 (Even if you don't have NetBeans.) (即使您没有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. 因为您知道测试执行之前的$user_id值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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